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之间的转换是默认的,具有内置导航控制器的弹出手势.
希望这可以帮助!
Jes*_*sse 13
每次出现之前,您都需要设置委托 - 例如,在prepareForSeque中.如果要进行自定义转换,请将其设置为self.如果您想要默认转换(如默认弹出转换),请将其设置为nil.