纸上得来终觉浅,绝知此事要躬行。

0%

监听UINavigationController-滑动返回手势

1、添加代理 UINavigationControllerDelegate

1
2
3
4
5
6
7
8
9
10
11
12
13
- (void)viewWillAppear:(BOOL)animated{
[super viewWillAppear:animated];
[self.navigationController.navigationBar setHidden:YES];
if ([[[UIDevice currentDevice] systemVersion] floatValue] > 7.0) {
self.navigationController.delegate = self;
}
}

- (void)viewWillDisappear:(BOOL)animated{
if ([[[UIDevice currentDevice] systemVersion] floatValue] > 7.0) {
self.navigationController.delegate = nil;
}
}

2、实现代理方法

1
2
3
4
5
6
7
//监听滑动手势
- (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated{
id <UIViewControllerTransitionCoordinator>tc = navigationController.topViewController.transitionCoordinator;
[tc notifyWhenInteractionChangesUsingBlock:^(id<UIViewControllerTransitionCoordinatorContext> _Nonnull context) {
[dataKit kit].reloadFlage = [context isCancelled];
}];
}

[context isCancelled] 是BOOL类型,未返回[context isCancelled]==YES,返回成功[context isCancelled]==NO。

点击按钮返回 或使用 [navigationController popviewcontorller] 不进入此回调。