InteractivePopGestureRecognizer causing app freezing

前端 未结 9 1803
再見小時候
再見小時候 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 10:49

    I had same issue and I found below solution. add below controller

    #import 
    @interface CBNavigationController : UINavigationController     
    @end
    
    #import "CBNavigationController.h"
    @interface CBNavigationController ()
    @end
    @implementation CBNavigationController
    - (void)viewDidLoad
    {
    NSLog(@"%s",__FUNCTION__);
    __weak CBNavigationController *weakSelf = self;
    
    if ([self respondsToSelector:@selector(interactivePopGestureRecognizer)])
    {
        self.interactivePopGestureRecognizer.delegate = weakSelf;
        self.delegate = weakSelf;
    }
    }
    
    - (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated
    {
    NSLog(@"%s",__FUNCTION__);
    
    if ([self respondsToSelector:@selector(interactivePopGestureRecognizer)])
        self.interactivePopGestureRecognizer.enabled = NO;
    
    [super pushViewController:viewController animated:animated];
    }
    
    #pragma mark UINavigationControllerDelegate
    - (void)navigationController:(UINavigationController *)navigationController
       didShowViewController:(UIViewController *)viewController
                    animated:(BOOL)animate
    {
    NSLog(@"%s",__FUNCTION__);
    
    // Enable the gesture again once the new controller is shown
    
    if ([self respondsToSelector:@selector(interactivePopGestureRecognizer)])
        self.interactivePopGestureRecognizer.enabled = YES;
    }
    @end
    

    Can refer below link

    http://keighl.com/post/ios7-interactive-pop-gesture-custom-back-button/

提交回复
热议问题