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;
}
裡解決的,但似乎有待欠妥當。
/僅自己查漏補缺用,如有問題,歡迎指出