iOS 7自定义过渡故障

时间:2013-10-28 02:35:37

标签: ios objective-c uiviewcontroller ios7

此视频显示了我遇到的问题。 http://www.youtube.com/watch?v=C9od_2KZAbs

我正在尝试使用UIPanGestureRecognizer创建自定义推送交互式转换。我有一个交互式转换委托(使用UIPercentDrivenInteractiveTransition)和一个过渡动画师。

以下是平移手势控制转换的方式:

- (void) panGestureRecognized:(UIPanGestureRecognizer *) gestureRecogznier {

    CGPoint translation = [gestureRecogznier translationInView:gestureRecogznier.view];

    if (gestureRecogznier.state == UIGestureRecognizerStateBegan) {

        self.interactiveTransitionAnimator = [[UIPercentDrivenInteractiveTransition alloc] init];

        EVDetailViewController *detailViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"EVDetailViewController"];
        [self.navigationController pushViewController:detailViewController animated:YES];
    }
    else if (gestureRecogznier.state == UIGestureRecognizerStateChanged) {

        CGFloat d = (translation.x / CGRectGetWidth(self.view.bounds)) * -1;
        [self.interactiveTransitionAnimator updateInteractiveTransition:d];
    }
    else if (gestureRecogznier.state == UIGestureRecognizerStateEnded) {

        if ([gestureRecogznier velocityInView:self.view].x < 0) {
            [self.interactiveTransitionAnimator finishInteractiveTransition];
        } else {
            [self.interactiveTransitionAnimator cancelInteractiveTransition];
        }

        self.interactiveTransitionAnimator = nil;
    }
}

UINavigationControllerDelegate处理转发委托对象的自动售货,这是在调用pushViewController:时触发的。

过渡动画师有一个非常简单的动画:

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

    UIViewController* toViewController = [transitionContext viewControllerForKey:UITransitionContextToViewControllerKey];
    [[transitionContext containerView] addSubview:toViewController.view];

    CGRect finalToVCFrame = [transitionContext finalFrameForViewController:toViewController];

    if (self.operation == UINavigationControllerOperationPush) {

        // set offscreen to the right
        toViewController.view.frame = CGRectMake(320.0f, 0.0f, 320.0f, 568.0f);

        [UIView animateWithDuration:[self transitionDuration:transitionContext] delay:0.0f options:0 animations:^{

            toViewController.view.frame = finalToVCFrame;

        } completion:^(BOOL finished) {

            // *** When this is called, the glitch occurs
            [transitionContext completeTransition:YES];
        }];
    }
}

在视频中,平移手势大约结束了60%,这触发了finishInteractiveTransition调用。一切顺利,直到UIView基于块的动画中的完成块调用completeTransition:。调用此方法时,toViewController将不必要地重新设置推送动画的最后一部分。在视频中,红色视图是窗口。动画持续时间为3秒。

我无法弄清楚为什么会这样。它看起来像手势结束时和动作完成传递之间的动画发生两次。有什么想法吗?

4 个答案:

答案 0 :(得分:19)

从iOS 7.1开始,我可以在模拟器中重现这一点,但不能在实际设备上重现。无论如何,似乎有一种解决方法:

self.interactiveTransitionAnimator.completionSpeed = 0.999;

这个错误有一个雷达:rdar://14675246

答案 1 :(得分:2)

如果您在致电[transitionContext completeTransition:YES];之后立即致电finishInteractiveTransition,会发生什么情况:

else if (gestureRecogznier.state == UIGestureRecognizerStateEnded) {

    if ([gestureRecogznier velocityInView:self.view].x < 0) {
        [self.interactiveTransitionAnimator finishInteractiveTransition];
        [transitionContext completeTransition:YES];
    } else {
        [self.interactiveTransitionAnimator cancelInteractiveTransition];
    }

    self.interactiveTransitionAnimator = nil;
}

答案 2 :(得分:1)

我有一个例子on github没有故障。如果您还有其他问题,请与我们联系。

答案 3 :(得分:0)

或者,当matt观察到here时,您也可以推迟completeTransition或自行驾驶自定义互动控制器:

  

我见过类似的东西。我有两种可能的解决方法。一种是在动画完成处理程序中使用延迟性能:

   } completion:^(BOOL finished) {
            double delayInSeconds = 0.1;
            dispatch_time_t popTime = 
                 dispatch_time(DISPATCH_TIME_NOW, (int64_t)(delayInSeconds * NSEC_PER_SEC));
            dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
                BOOL cancelled = [transitionContext transitionWasCancelled];
                [transitionContext completeTransition:!cancelled];
            });
           self.interacting = NO;
    }];
     

另一种可能性是:不要使用百分比驱动动画!我自己手动驾驶交互式自定义动画时,从未遇到过这样的问题。