我遇到了一个问题,我在下面进行了描述。
我在用UIViewControllerContextTransitioning
用于自定义过渡。
我有 2 个视图控制器,第一个视图控制器和第二个视图控制器。
现在我想在第一个视图控制器上添加第二个视图控制器并带有动画。我已经实现了,现在第二个视图控制器是透明的,所以我们可以在第二个视图控制器下面看到第一个视图控制器。
但我看不到第一个视图控制器,并且我只能看到第二个视图控制器下面的黑屏。
-(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];
}];
}
When [self.transitionContext completeTransition:YES];
调用后,突然第一个视图控制器消失,第二个视图控制器下方显示黑屏。
有人有想法吗?
谢谢。
我在这里遇到了同样的问题 – 看起来像是 iOS 8 中的一个错误。我已经提交雷达.
I used Reveal屏幕变黑后检查视图层次结构。钥匙UIWindow
完全是空的——根本没有视图层次结构!
![Reveal'd](https://i.stack.imgur.com/QHZDu.png)
我玩了一下,看起来对于简单的情况有一个简单的解决方法。您只需重新添加toViewController
的视图作为关键窗口的子视图:
transitionContext.completeTransition(true)
UIApplication.sharedApplication().keyWindow!.addSubview(toViewController.view)
我已经检查过了,钥匙窗口的rootViewController
仍然正确设置,所以没关系。我不确定如果您从已呈现的模态控制器中呈现控制器会发生什么,因此对于更复杂的情况,您必须进行试验。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)