“来自视图控制器”使用UIViewControllerContextTransitioning消失 [英] "From View Controller" disappears using UIViewControllerContextTransitioning

查看:237
本文介绍了“来自视图控制器”使用UIViewControllerContextTransitioning消失的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I got one problem and i have described it below.

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

I am using UIViewControllerContextTransitioning for custom transitions.

我有2个视图控制器,第一个视图控制器和第二个视图控制器。

I have 2 view controllers , first view controller and second view controller.

现在我想在带有动画的第一个视图控制器上添加第二视图控制器。我已经实现了,现在我有第二视图控制器透明,所以我们可以看到第二视图控制器下面的第一个视图控制器。

Now i want to add secondview controller on first view controller with animation. I have achieved it, now I have secondview controller transparent , so we can see first view controller below secondview controller.

但是我无法看到第一个视图控制器,并且我只能看到第二视图控制器下面的黑屏。

But i am not able to see first view controller , and i can see only black screen below secondview 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]时; 调用,突然第一个视图控制器消失,黑屏显示在第二个视图控制器下面。

When [self.transitionContext completeTransition:YES]; called, suddenly the first view controller disappears and black screen displays below second view controller.

有人有想法吗?
谢谢。

Does any one have idea ? Thanks.

推荐答案

我在这里遇到了同样的问题 - 看起来像iOS 8中的一个错误。我已经提交了雷达

I was having the same problem here – looks like a bug in iOS 8. I've filed a radar.

我在屏幕显示后使用显示检查视图层次结构黑色。键 UIWindow 完全为空 - 根本没有视图层次结构!

I used Reveal to inspect the view hierarchy after the screen goes black. The key UIWindow is completely empty – no view hierarchy at all!

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

I played around a bit and it looks like there is an easy workaround, for simple cases. You can just re-add the toViewController's view as a subview of the key window's:

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

我已经检查过了,关键窗口的 rootViewController 仍然正确设置,所以没关系。我不确定如果你从一个已经呈现的模态控制器中展示你的控制器会发生什么,所以对于更复杂的情况,你将不得不试验一下。

I've checked and the key window's rootViewController is still correctly set, so that's fine. I'm not sure what would happen if you presented your controller from within an already presented modal controller, so for more complex cases, you'll have to experiment around.

这篇关于“来自视图控制器”使用UIViewControllerContextTransitioning消失的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆