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

jus*_*mmy 13 objective-c ios ios7

所以我有一个UINavigationController,控制器A作为根控制器.

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

当我想将Controller C推到最顶层时,我想回到UINavigationController附带的默认推/弹转换.为了实现这一点,我返回零

navigationController:animationControllerForOperation:fromViewController:toViewController:
Run Code Online (Sandbox Code Playgroud)

但是,如果你返回nil,那么

navigationController:interactionControllerForAnimationController:
Run Code Online (Sandbox Code Playgroud)

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

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

或者其他一些方式?

max*_*lov 19

您应该将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;
}
Run Code Online (Sandbox Code Playgroud)

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

希望这可以帮助!

  • 根据 Apple 的 DTS 人员的说法,UINavigationController 附带的私有 InteractivePopGestureRecognizer 在其委托中进行了许多检查,其中一些检查调用私有 API。实现您自己的委托并不能保证覆盖 100% 的所有情况。 (2认同)

Jes*_*sse 13

每次出现之前,您都需要设置委托 - 例如,在prepareForSeque中.如果要进行自定义转换,请将其设置为self.如果您想要默认转换(如默认弹出转换),请将其设置为nil.

  • 遗憾的是,这实际上是Apple DTS人员推荐的正确答案和方法,即使它不是特别优雅的.基本上你需要有2个UINavigationControllerDelegate对象,一个实现转换回调,另一个没有(或者是nil).要获取默认弹出过渡,请使用不带回调的委托(或将委托设置为nil).要获得自定义转换,请替换具有回调的委托(并在转换完成后恢复原始委托). (3认同)
  • 这仍然是推荐的方法吗? (2认同)