- 自定义UINavigationController。
@interface JKNavigationController () <UINavigationControllerDelegate, UIGestureRecognizerDelegate>
- 重构viewDidLoad方法。
- (void)viewDidLoad {
[super viewDidLoad];
// 为self创建弱引用对象
__weak typeof (self) weakSelf = self;
if ([self respondsToSelector:@selector(interactivePopGestureRecognizer)]) {
self.interactivePopGestureRecognizer.delegate = weakSelf;
self.delegate = weakSelf;
}
}
- 重构pushViewController方法。
- (void)pushViewController:(UIViewController *)viewController
animated:(BOOL)animated {
if ([self respondsToSelector:@selector(interactivePopGestureRecognizer)]) {
self.interactivePopGestureRecognizer.enabled = NO;
}
[super pushViewController:viewController animated:animated];
}
- 实现UINavigationControllerDelegate的方法。
- (void)navigationController:(UINavigationController *)navigationController
didShowViewController:(UIViewController *)viewController
animated:(BOOL)animated {
if ([self respondsToSelector:@selector(interactivePopGestureRecognizer)]) {
self.interactivePopGestureRecognizer.enabled = YES;
}
}
网友评论