所以我有一个UINavigationController,控制器A作为根控制器。
当我想将Controller推到顶部时,我希望使用自定义动画转换和自定义交互转换。这个很好用。
当我想将Controller推到顶部时,我想回到默认的 push/pop转换,即UINavigationController附带的转换。为了实现这一目标,我返回零
navigationController:animationControllerForOperation:fromViewController:toViewController:
然而,如果你返回零,那么
navigationController:interactionControllerForAnimationController:
永远不会被调用,默认的“从左边边缘开始”的弹出交互转换不起作用。
是否有方法返回默认的push/pop动画控制器和交互控制器?(是否有id<UIViewControllerAnimatedTransitioning>
和id<UIViewControllerInteractiveTransitioning>
的具体实现?)
还是其他方式?
发布于 2014-01-04 08:22:36
应该将NavigationController的interactivePopGestureRecognizer委托设置为self,然后在-gestureRecognizerShouldBegin中处理其行为:
也就是说,当您希望内置的pop手势启动时,您必须从此方法返回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;
}
您可以查看您的场景的样本工程。视图控制器A和B之间的转换是自定义动画,自定义B->A弹出手势。视图控制器B和C之间的转换是默认的,内置导航控制器的pop手势。
希望这能有所帮助!
发布于 2014-01-13 19:03:04
在出现之前,每次都需要设置委托--例如,在prepareForSeque中。如果您想要自定义转换,请将其设置为self。如果您想要默认的转换(如默认的pop转换),则将其设置为零。
发布于 2015-04-02 03:40:58
在每个转换之前/之后设置委托是一个有效的解决办法,但如果您实现了其他UINavigationControllerDelegate
的方法,并且需要保留它们,您可以按照Ziconic的建议拥有2个委托对象,也可以使用NSObject的respondsToSelector:
。在导航委托中,您可以实现:
- (BOOL)respondsToSelector:(SEL)aSelector
{
if (aSelector == @selector(navigationController:animationControllerForOperation:fromViewController:toViewController:) ||
aSelector == @selector(navigationController:interactionControllerForAnimationController:)) {
return self.interactivePushTransitionEnabled;
}
return [super respondsToSelector:aSelector];
}
然后,您应该确保根据需要更新interactivePushTransitionEnabled
。在您的示例中,只有在显示控制器A时,才应该将属性设置为YES
。
还有一件事要做:强制UINavigationController重新评估其委托实现的方法。这样做是很容易做到的:
navigationController.delegate = nil;
navigationController.delegate = self; // or whatever object you use as the delegate
https://stackoverflow.com/questions/20113701
复制相似问题