iOS 7自定义过渡故障 [英] iOS 7 custom transition glitch

查看:70
本文介绍了iOS 7自定义过渡故障的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

This video shows the issue I am having. http://www.youtube.com/watch?v=C9od_2KZAbs

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

I am attempting to create a custom push interactive transition using a UIPanGestureRecognizer. I have an interactive transition delegate (using UIPercentDrivenInteractiveTransition) and a transition animator.

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

Here is how the pan gesture controls the transition:

- (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:时触发。

The UINavigationControllerDelegate handles the vending of both transition delegate objects, which is triggered when pushViewController: is called.

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

The transition animator has a very simple animation:

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

In the video, the pan gesture ends about 60% of the way through, which triggers the finishInteractiveTransition call. Everything goes smoothly until the completion block in the UIView block-based animation calls completeTransition:. When this method is called, the toViewController re-animates the last part of the push animation unnecessarily. In the video the red view is the window. The animation duration is 3 seconds.

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

I cannot figure out why this happens. It looks like the animation between the point when the gesture ends and when completeTransition: is called happens twice. Any ideas?

推荐答案

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

As of iOS 7.1, I can reproduce this in simulator but not on an actual device. Anyway, there appears to be a workaround:

self.interactiveTransitionAnimator.completionSpeed = 0.999;

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

There is a radar for this bug: rdar://14675246

这篇关于iOS 7自定义过渡故障的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆