iOS7自定义转换调用两次

时间:2014-07-03 16:38:05

标签: ios ios7 uitabbarcontroller transitions

我想为UITabBarController的标签之间的转换设置动画。出于某种原因,UIViewControllerAnimatedTransitioning协议中的此方法被调用两次:

- (void)animateTransition:(id<UIViewControllerContextTransitioning>)transitionContext

堆栈跟踪: enter image description here 紧接着: enter image description here 此外,- (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];
    }];

}

1 个答案:

答案 0 :(得分:0)

对于第一次展示,我认为- (void)animationEnded:(BOOL)transitionCompleted会被调用两次,因为您调用基于Apple文档的[transitionContext completeTransition:YES]

  

在动画完成后调用此方法以通知系统已完成过渡动画。此方法的默认实现调用动画师的 animationEnded :方法,使其有机会执行最后一分钟的清理。

如果UIViewControllerAnimatedTransitioning被调用两次,那么就去吧。

为了进一步分析为什么UIViewControllerAnimatedTransitioning被调用两次,我很高兴看到您的animationControllerForPresentedControlleranimationControllerForDismissedController实施。