2

我正在使用一个自定义的左菜单控制器,它只能在它的顶级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

4

0 回答 0