iOS 7自定义转换与UINavigationController

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

我正在尝试使用UIPanGestureRecognizer创建自定义交互式推送转换.我有一个交互式转换委托(使用UIPercentDrivenInteractiveTransition)和一个过渡动画师. completeTransition:似乎不必要地重新动画推动.

以下是平移手势如何控制转换:

- (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秒.

我不知道为什么会发生这种情况.看起来像手势结束点之间的动画和completeTransition:被调用发生两次.有任何想法吗?

解决方法

找到一个工作的解决方法.

添加

dispatch_async(dispatch_get_global_queue(disPATCH_QUEUE_PRIORITY_BACKGROUND,0),^{
        [transitionContext completeTransition:![transitionContext transitionWasCancelled]];
    });

在你的完成处理程序.

为我工作

相关文章

UITabBarController 是 iOS 中用于管理和显示选项卡界面的一...
UITableView的重用机制避免了频繁创建和销毁单元格的开销,使...
Objective-C中,类的实例变量(instance variables)和属性(...
从内存管理的角度来看,block可以作为方法的传入参数是因为b...
WKWebView 是 iOS 开发中用于显示网页内容的组件,它是在 iO...
OC中常用的多线程编程技术: 1. NSThread NSThread是Objecti...