iOS 7仅在某些时候使用自定义交互式过渡 [英] iOS 7 use custom interactive transitions only some of the time
问题描述
所以我有一个UINavigationController,控制器A作为根控制器。
So I have a UINavigationController, with Controller A as the root controller.
当我想将控制器B放在最顶层时,我想使用自定义动画过渡和自定义交互式转换。这很好。
When I want to push Controller B on top, I want to use a custom animated transition and a custom interactive transition. This works fine.
当我想将控制器C推到最顶层时,我想回到 默认 UINavigationController附带的推/弹转换。为了实现这一点,我返回nil for
When I want to push Controller C on top, I want to fall back to the default push/pop transitions that comes with UINavigationController. To make this happen I return nil for
navigationController:animationControllerForOperation:fromViewController:toViewController:
但是如果你返回nil,那么
however if you return nil, then
navigationController:interactionControllerForAnimationController:
将永远不会被调用,默认的从左边缘平移弹出交互式转换不会不行。
will never be called and the default "pan from left edge" pop interactive transition doesn't work.
有没有办法返回默认的推/动画动画控制器和交互控制器?
(是否有具体的 id< UIViewControllerAnimatedTransitioning>
和 id< UIViewControllerInteractiveTransitioning>
?)
Is there a way to return the default push/pop animation controller and interaction controller?
(Are there concrete implementations of id<UIViewControllerAnimatedTransitioning>
and id<UIViewControllerInteractiveTransitioning>
?)
还是其他一些方式?
推荐答案
你应该将NavigationController的interactivePopGestureRecognizer委托设置为自我然后在-gestureRecognizerShouldBegin中处理它的行为:
You should set NavigationController's interactivePopGestureRecognizer delegate to self and then handle its behavior in -gestureRecognizerShouldBegin:
也就是说,当你想要触发内置的pop手势时,你必须从这个方法返回YES。你的自定义手势也一样 - 你必须找出你正在处理的识别器。
That is, when you want the built-in pop gesture to fire, you must return YES from this method. The same goes for your custom gestures - you have to figure out which recognizer you are dealing with.
- (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之间的转换是默认的,具有内置导航控制器的弹出手势。
You can check out a sample project for your scenario. Transitions between view controllers A and B are custom animated, with custom B->A pop gesture. Transitions between view controllers B and C are default, with built-in navigation controller's pop gesture.
希望这有帮助!
这篇关于iOS 7仅在某些时候使用自定义交互式过渡的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!