我想为 UITabBarController
的选项卡之间的过渡设置动画。 .出于某种原因,此方法来自 UIViewControllerAnimatedTransitioning
协议(protocol)被调用两次:
- (void)animateTransition:(id<UIViewControllerContextTransitioning>)transitionContext
堆栈跟踪:
紧接着:
还有
- (void)animationEnded:(BOOL)transitionCompleted
方法被调用两次。我不知道为什么。
这是代码:
- (void)animateTransition:(id<UIViewControllerContextTransitioning>)transitionContext {
UIView *containerView = [transitionContext containerView];
UIViewController *fromVC = [transitionContext viewControllerForKey:UITransitionContextFromViewControllerKey];
UIViewController *toVC = [transitionContext viewControllerForKey:UITransitionContextToViewControllerKey];
[toVC.view setTransform:CGAffineTransformMakeTranslation(320, 0)];
[containerView addSubview:toVC.view];
[UIView animateWithDuration:0.5 animations:^{
[toVC.view setTransform:CGAffineTransformIdentity];
[fromVC.view setTransform:CGAffineTransformMakeTranslation(-320, 0)];
} completion:^(BOOL finished) {
[fromVC.view setTransform:CGAffineTransformIdentity];
[toVC.view setTransform:CGAffineTransformIdentity];
[transitionContext completeTransition:YES];
}];
}
最佳答案
对于第一印象,我相信 - (void)animationEnded:(BOOL)transitionCompleted
被调用两次,因为你调用了 [transitionContext completeTransition:YES]
,它基于苹果文档:
Call this method after your animations have completed to notify the system that the transition animation is done. The default implementation of this method calls the animator’s animationEnded: method to give it a chance to perform any last minute cleanup.
如果
UIViewControllerAnimatedTransitioning
被调用两次然后就可以了。进一步分析为什么
UIViewControllerAnimatedTransitioning
被叫了两次我很高兴看到你的animationControllerForPresentedController
和 animationControllerForDismissedController
执行。
关于iOS7自定义过渡调用了两次,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24559139/