1、interactivePopGestureRecognizer是UISreenEdgePanGestureRecognizer的子类。
2. 当使用手势,返回时要监听是否真正返回,然后添加相应的消息传递。
首先想到是通过手势delegate的监听来完成。
- (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer。发现手势每次都会触发此方法。无法判断是否成功返回。
然后想到了用navigationController的delegate来监听。果然能达到想要效果
#pragma mark - UINavigationControllerDelegate
- (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated {
id<UIViewControllerTransitionCoordinator> tc = navigationController.topViewController.transitionCoordinator;
[tc notifyWhenInteractionEndsUsingBlock:^(id<UIViewControllerTransitionCoordinatorContext> context) {
NSLog(@" Is cancelled: %i", [context isCancelled]);
if (![context isCancelled]) {
/ do something (update UI )
}
}];
}
但,我在更改NavigationControllerDelegate时想要保存之前的<UINavigationControllerDelegate>,以便返回后再将代理更改回去。
navigationDelegate = self.navigationController.delegate;
self.navigationController.delegate = self;
if (![context isCancelled]) {
self.navigationController.delegate = navigationDelegate;
}
但并不是想像中那么美好,无法再给代理赋给之前的对象,实际上是能获取到navigationDelegate的对象,但为什么之前的对象不能再响应 UINavigationControllerDelegate 的代理了,我也没太搞清,希望有知道者能告诉我…
我是把代理更改放到
- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
self.navigationController.delegate = self;
}
里解决的,但似乎有待欠妥当。
/仅自己查漏补缺用,如有问题,欢迎指出