iOS 7仅在一些时间使用自定义交互式转换

前端之家收集整理的这篇文章主要介绍了iOS 7仅在一些时间使用自定义交互式转换前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
所以我有一个UINavigationController,控制器A作为根控制器.

当我想要将控制器B推到顶部时,我想使用自定义的动画转换和自定义的交互式转换.这工作正常

当我想把控制器C放在顶部时,我想回到UINavigationController附带的默认push / pop转换.为了使这一切发生,我返回零

navigationController:animationControllerForOperation:fromViewController:toViewController:

然而,如果你返回零,那么

navigationController:interactionControllerForAnimationController:

将永远不会被调用,默认的“从左边缘的平移”弹出交互式转换不起作用.

有没有办法返回默认的push / pop动画控制器和交互控制器?
(是否具有id< UIViewControllerAnimatedTransitioning>和id< UIViewControllerInteractiveTransitioning>?)的具体实现)

还是其他一些方法

解决方法

您应该将NavigationController的interactivePopGestureRecognizer委托设置为self,然后在-gestureRecognizerShouldBegin中处理其行为:

也就是说,当您想要内置的流行手势触发时,您必须从此方法返回YES.您的自定义手势也同样如此 – 您必须弄清楚您正在处理哪个识别器.

- (void)setup
{
    self.interactiveGestureRecognizer = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(handleTransitionGesture:)];
    self.interactiveGestureRecognizer.delegate = self;
    [self.navigationController.view addGestureRecognizer:self.interactiveGestureRecognizer];

    self.navigationController.interactivePopGestureRecognizer.delegate = self;
}

- (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer
{
    // Don't handle gestures if navigation controller is still animating a transition
    if ([self.navigationController.transitionCoordinator isAnimated])
        return NO;

    if (self.navigationController.viewControllers.count < 2)
        return NO;

    UIViewController *fromVC = self.navigationController.viewControllers[self.navigationController.viewControllers.count-1];
    UIViewController *toVC = self.navigationController.viewControllers[self.navigationController.viewControllers.count-2];

    if ([fromVC isKindOfClass:[ViewControllerB class]] && [toVC isKindOfClass:[ViewControllerA class]])
    {
        if (gestureRecognizer == self.interactiveGestureRecognizer)
            return YES;
    }
    else if (gestureRecognizer == self.navigationController.interactivePopGestureRecognizer)
    {
        return YES;
    }

    return NO;
}

您可以查看您的场景的sample project.视图控制器A和B之间的转换是自定义动画的,具有自定义的B-> A流行手势.视图控制器B和C之间的转换是默认的,内置导航控制器的弹出手势.

希望这可以帮助!

猜你在找的iOS相关文章