我想为UITabBarController
的标签之间的转换设置动画。出于某种原因,UIViewControllerAnimatedTransitioning
协议中的此方法被调用两次:
- (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];
}];
}
答案 0 :(得分:0)
对于第一次展示,我认为- (void)animationEnded:(BOOL)transitionCompleted
会被调用两次,因为您调用基于Apple文档的[transitionContext completeTransition:YES]
:
在动画完成后调用此方法以通知系统已完成过渡动画。此方法的默认实现调用动画师的 animationEnded :方法,使其有机会执行最后一分钟的清理。
如果UIViewControllerAnimatedTransitioning
被调用两次,那么就去吧。
为了进一步分析为什么UIViewControllerAnimatedTransitioning
被调用两次,我很高兴看到您的animationControllerForPresentedController
和animationControllerForDismissedController
实施。