我想在presentViewController
期间制作动画:
- (void)animateTransition:(id<UIViewControllerContextTransitioning>)transitionContext {
UIViewController *fromVC = [transitionContext viewControllerForKey:UITransitionContextFromViewControllerKey];
UIViewController *toVC = [transitionContext viewControllerForKey:UITransitionContextToViewControllerKey];
UIView *toView = toVC.view;
UIView *fromView = fromVC.view;
UIView* containerView = [transitionContext containerView];
[containerView addSubview:toView];
NSTimeInterval duration = 0.35;
[UIView transitionFromView:fromView toView:toView duration:duration options:(self.reverse?UIViewAnimationOptionTransitionFlipFromLeft:UIViewAnimationOptionTransitionFlipFromRight) |
UIViewAnimationOptionAllowUserInteraction completion:^(BOOL finished) {
[transitionContext completeTransition:![transitionContext transitionWasCancelled]];
}];
}
这在iOS7上工作正常,但iOS8上没有动画。
答案 0 :(得分:2)
+transitionFromView:toView:duration:options:completion:
负责处理视图层次结构。你不应该[containerView addSubview:toView]
。
+transitionFromView:toView:duration:options:completion:
的内容中的某处应该是以下代码:
UIView *superview = fromView.superview;
[fromView removeFromSuperview];
[superview addSubview:toView];
您是否尝试删除containerView
代码:
- (void)animateTransition:(id<UIViewControllerContextTransitioning>)transitionContext {
UIViewController *fromVC = [transitionContext viewControllerForKey:UITransitionContextFromViewControllerKey];
UIViewController *toVC = [transitionContext viewControllerForKey:UITransitionContextToViewControllerKey];
UIView *toView = toVC.view;
UIView *fromView = fromVC.view;
NSTimeInterval duration = 0.35;
[UIView transitionFromView:fromView toView:toView duration:duration options:(self.reverse?UIViewAnimationOptionTransitionFlipFromLeft:UIViewAnimationOptionTransitionFlipFromRight) |
UIViewAnimationOptionAllowUserInteraction completion:^(BOOL finished) {
[transitionContext completeTransition:![transitionContext transitionWasCancelled]];
}];
}
答案 1 :(得分:1)
尝试为您的代码所在的视图控制器关闭Use Autolayout
。它现在应该可以正常工作。这个对我有用。当我为iOS8设置项目时,我的动画被破坏了,但删除Auto Layout
允许它们工作。