ios - "From View Controller"使用 UIViewControllerCon

我遇到了一个问题,我在下面进行了描述。

我正在使用 UIViewControllerContextTransitioning 进行自定义转换。

我有 2 个 View Controller ,第一个 View Controller 和第二个 View Controller 。

现在我想用动画在第一个 View Controller 上添加第二个 View Controller 。我已经实现了,现在第二个 View Controller 是透明的,所以我们可以在第二个 View Controller 下面看到第一个 View Controller 。

但是我看不到第一个 View Controller ,我只能看到第二个 View Controller 下方的黑屏。

-(void)animateTransition:(id<UIViewControllerContextTransitioning>)transitionContext{
    self.transitionContext = transitionContext;
    if(self.isPresenting){
        [self executePresentationAnimation:transitionContext];
    }
    else{
       [self executeDismissalAnimation:transitionContext];
    }
  }

-(void)executePresentationAnimation:(id<UIViewControllerContextTransitioning>)transitionContext{
     UIView* inView = [transitionContext containerView];
     UIViewController* toViewController = [transitionContext viewControllerForKey:UITransitionContextToViewControllerKey];

     UIViewController* fromViewController = [transitionContext viewControllerForKey:UITransitionContextFromViewControllerKey];

     CGRect offScreenFrame = inView.frame;
     offScreenFrame.origin.y = inView.frame.size.height;
     toViewController.view.frame = offScreenFrame;

    toViewController.view.backgroundColor = [UIColor clearColor];
    fromViewController.view.backgroundColor = [UIColor clearColor];
    inView.backgroundColor = [UIColor  clearColor];
    [inView insertSubview:toViewController.view aboveSubview:fromViewController.view];
     // [inView addSubview:toViewController.view];
    CFTimeInterval duration = self.presentationDuration;
    CFTimeInterval halfDuration = duration/2;

    CATransform3D t1 = [self firstTransform];
    CATransform3D t2 = [self secondTransformWithView:fromViewController.view];

    [UIView animateKeyframesWithDuration:halfDuration delay:0.0 options:UIViewKeyframeAnimationOptionCalculationModeLinear animations:^{

    [UIView addKeyframeWithRelativeStartTime:0.0f relativeDuration:0.5f animations:^{
        fromViewController.view.layer.transform = t1;
    }];

    [UIView addKeyframeWithRelativeStartTime:0.5f relativeDuration:0.5f animations:^{
        fromViewController.view.layer.transform = t2;
    }];
    } completion:^(BOOL finished) {
    }];


    [UIView animateWithDuration:duration delay:(halfDuration - (0.3*halfDuration)) usingSpringWithDamping:0.7f initialSpringVelocity:6.0f options:UIViewAnimationOptionCurveEaseIn animations:^{
        toViewController.view.frame = inView.frame;
    } completion:^(BOOL finished) {
        [self.transitionContext completeTransition:YES];
    }];
}

[self.transitionContext completeTransition:YES]; 调用时,第一个 View Controller 突然消失,第二个 View Controller 下方显示黑屏。

有人知道吗? 谢谢。

最佳答案

我在这里遇到了同样的问题 - 看起来像是 iOS 8 中的一个错误。我有 filed a radar .

我使用了 Reveal在屏幕变黑后检查 View 层次结构。 UIWindow 键完全为空——根本没有 View 层次结构!

我玩了一下,看起来有一个简单的解决方法,对于简单的情况。您可以将 toViewController 的 View 重新添加为关键窗口的 subview :

transitionContext.completeTransition(true)
UIApplication.sharedApplication().keyWindow!.addSubview(toViewController.view)

我已经检查过了,关键窗口的 rootViewController 仍然设置正确,所以没问题。我不确定如果您从已经呈现的模态 Controller 中呈现 Controller 会发生什么,因此对于更复杂的情况,您必须进行试验。

关于ios - "From View Controller"使用 UIViewControllerContextTransitioning 消失,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24338700/

相关文章:

ios - UIAlertView 首先弃用 IOS 9

ios - UICollectionViewCell 上的长按手势

ios - 对 UITableView 使用 didSelectRowAtIndexPath 或 p

ios - 如何让 UILabel 显示轮廓文本?

objective-c - iOS 7.0.3 上的 "HelveticaNeue-Italic"发

ios - UICollectionView 当前可见单元格索引

ios - 带有透明孔的 CALayer

ios - 如何将度数转换为弧度?

objective-c - iOS8 - 约束含糊地暗示高度为零

ios - 设置 UILabel 行距