解决一级页面手势返回页面卡死

今天在测试程序的时候发现一个bug,在一级页面左右滑动后,再点击页面按钮页面会卡死,原因是一级页面没有上级页面,必须禁掉手势返回。

#pragma mark *********解决一级页面手势返回卡死的情况**********
- (void)viewDidAppear:(BOOL)animated
{
    [super viewDidAppear:animated];
    if ([self.navigationController respondsToSelector:@selector(interactivePopGestureRecognizer)])
    {
        self.navigationController.interactivePopGestureRecognizer.enabled = NO;
    }
}
- (void)viewDidDisappear:(BOOL)animated
{
    if ([self.navigationController respondsToSelector:@selector(interactivePopGestureRecognizer)])
    {
        self.navigationController.interactivePopGestureRecognizer.enabled = YES;
    }
}

方法二:

#pragma mark *********解决一级页面手势返回卡死的情况**********
- (void)viewDidAppear:(BOOL)animated
{
    [super viewDidAppear:animated];
    self.isCanSideBack = NO;
    if ([self.navigationController respondsToSelector:@selector(interactivePopGestureRecognizer)])
    {
        self.navigationController.interactivePopGestureRecognizer.delegate=self;
    }
}

- (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer*)gestureRecognizer {

   return self.isCanSideBack;
}

- (void)viewDidDisappear:(BOOL)animated
{
    self.isCanSideBack=YES;
    if ([self.navigationController respondsToSelector:@selector(interactivePopGestureRecognizer)])
    {
        self.navigationController.interactivePopGestureRecognizer.delegate = nil;
    }
}

实现- (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer*)gestureRecognizer需要继承 <UIGestureRecognizerDelegate>协议,是系统自己调用的!

推荐阅读更多精彩内容