iOS 7 仅在某些时候使用自定义交互过渡

标签 ios objective-c ios7

所以我有一个 UINavigationController, Controller A 作为根 Controller 。

当我想将 Controller B 推到顶部时,我想使用自定义动画过渡和自定义交互式过渡。这很好用。

当我想将 Controller C 推到顶部时,我想回退到 UINavigationController 附带的默认 推/弹出转换。为了实现这一点,我为

返回 nil
navigationController:animationControllerForOperation:fromViewController:toViewController:

但是如果你返回nil,那么

navigationController:interactionControllerForAnimationController:

永远不会被调用,并且默认的“从左边缘平移”弹出交互过渡不起作用。

有没有办法返回默认的推送/弹出动画 Controller 和交互 Controller ? (是否有 id<UIViewControllerAnimatedTransitioning>id<UIViewControllerInteractiveTransitioning> 的具体实现?)

还是其他方式?

最佳答案

您应该将 NavigationController 的 interactivePopGestureRecognizer 委托(delegate)设置为 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为你的场景。 View Controller A 和 B 之间的转换是自定义动画,使用自定义 B->A 弹出手势。 View Controller B 和 C 之间的转换是默认的,带有内置导航 Controller 的弹出手势。

希望这对您有所帮助!

关于iOS 7 仅在某些时候使用自定义交互过渡,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20113701/

相关文章:

ios - "Supported Interface Orientations"有先例吗?

html - iOS7 webkit 上的 Span 分词

ipad - 在 iOS 设备上安装开发的应用程序时会出错吗

ios - 在重用的原型(prototype)单元格中多次应用渐变蒙版

iphone - 如果(是)构造

ios - 如何使用新的 iOS 7 API 获取自动换行信息?

iOS 7 UITableView didSelectRowAtIndexPath pushViewController 编程,动画问题

iphone - 无法将对象变成故障(核心数据)

ios - CordovaError: promise 被拒绝,没有错误:错误代码65

ios - 从其他 subview 加载 ViewController 作为主视图中的 subview