我正在使用自定义左侧菜单控制器,当UIPanGestureRecognizer
仅位于顶级时,可以UINavigationController
打开。如果将某些UIViewController
推入堆栈,我希望interactivePopGestureRecognizer
按预期工作,并在用户从左向右滑动而不是打开左菜单时弹出VC。
为实现这一目标,我将UINavigationController
分为如下:
- (void)viewDidLoad {
[super viewDidLoad];
//[self.interactivePopGestureRecognizer setDelegate:nil];
[self.view addGestureRecognizer:[self createPanGestureRecognizer]];
}
- (UIPanGestureRecognizer *) createPanGestureRecognizer {
SGFPanGestureRecognizer * panRecognizer = [[SGFPanGestureRecognizer alloc] initWithTarget:self action:@selector(panGestureRecognized:)];
return panRecognizer;
}
-(void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated {
if(self.viewControllers.count == 1)
if(self.view.gestureRecognizers && self.view.gestureRecognizers.count>0)
for (UIGestureRecognizer * recog in self.view.gestureRecognizers)
{
if([recog isKindOfClass:[SGFPanGestureRecognizer class]]) {
[self.view removeGestureRecognizer:recog];
break;
}
}
[super pushViewController:viewController animated:animated];
}
-(UIViewController *)popViewControllerAnimated:(BOOL)animated {
UIViewController * vc = [super popViewControllerAnimated:animated];
if(self.viewControllers.count == 1)
[self.view addGestureRecognizer:[self createPanGestureRecognizer]];
return vc;
}
一切正常,除了一个:当我在detailViewController并从左向左滑动时,VC启动“POP”动画,它沿着我的手指。如果我将手势放得太快,那么detailViewController就不会真正弹出并回滚弹出动画。但是,此操作会触发popViewControllerAnimated
并且上面的逻辑变得毫无用处。
内容:
那么有没有办法了解是否过早释放滑动到后退的手势才能真正弹出UINavigationController
?