InteractivePopGestureRecognizer causing app freezing

前端 未结 9 1940
再見小時候
再見小時候 2021-01-31 10:29

In my app I have different controllers. When I push controller1 to navigation controller and swipe to back, all works good. But, if I push navigation controller1, and into contr

9条回答
  •  眼角桃花
    2021-01-31 11:04

    I had similar problem with freezing interface when using swipe-to-pop gesture. In my case the problem was in controller1.viewDidAppear I was disabling swipe gesture: self.navigationController.interactivePopGestureRecognizer.enabled = NO. So when user started to swipe back from contorller2, controller1.viewDidAppear was triggered and gesture was disabled, right during it's work.

    I solved this by setting self.navigationController.interactivePopGestureRecognizer.delegate = self in controller1 and implementing gestureRecognizerShouldBegin:, instead of disabling gesture recognizer:

    - (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer {
        if ([self.navigationController respondsToSelector:@selector(interactivePopGestureRecognizer)] &&
                gestureRecognizer == self.navigationController.interactivePopGestureRecognizer) {
            return NO;
        }
        return YES;
    }
    

提交回复
热议问题