iOS开发-NavigationController侧滑返回失效

//导致侧滑失效的设置
- navigationBarHidden
- navigationItem.hidesBackButton
- navigationItem.leftBarButtonItem/leftBarButtonItems

UINavigationController有一个交互手势

@property(nullable, nonatomic, readonly) UIGestureRecognizer *interactivePopGestureRecognizer NS_AVAILABLE_IOS(7_0) __TVOS_PROHIBITED;

解决方法

@interface SecondViewController () 
@property (nonatomic, strong) id originalDelegate;
@end
- (void)viewDidAppear:(BOOL)animated {
    [super viewDidAppear:animated];
    self.originalDelegate = self.navigationController.interactivePopGestureRecognizer.delegate;
    self.navigationController.interactivePopGestureRecognizer.delegate = self;
}

- (void)viewDidDisappear:(BOOL)animated {
    [super viewDidDisappear:animated];
    self.navigationController.interactivePopGestureRecognizer.delegate = self.originalDelegate;
    self.originalDelegate = nil;
}

修改侧滑手势的代理,注意在disappear的时候重置回去

你可能感兴趣的:(iOS开发-NavigationController侧滑返回失效)