坑一:自定義導航欄返回鍵 iOS7及之后版本 手勢邊緣右滑返回失效
解決方案:
-(void)viewDidLoad{ [super viewDidLoad]; //self 為 UINavigationController 子類 self.interactivePopGestureRecognizer.delegate=(id)self; }
網上千篇一律都是該答案,確實加了這句話可以手勢返回了,然而卻又埋下了新的坑。
坑二:在UINavigationController的rootViewController觸發手勢邊緣右滑,然后觸發push方法界面卡死,必須重新邊緣右滑后方可恢復,如下圖所示

解決方案:
坑二的問題主要是由坑一埋下的,為何出現坑二的情況並不清楚,有知道的麻煩告知謝謝。
-(void)viewDidLoad{ [super viewDidLoad]; self.interactivePopGestureRecognizer.delegate=(id)self; //實現UINavigationControllerDelegate協議 self.delegate = self; } //push完成 且界面顯示完成時 這個是Delegate的方法
- (void)navigationController:(UINavigationController *)navigationController didShowViewController:(UIViewController *)viewController animated:(BOOL)animated
{
if (navigationController.viewControllers.count == 1) {
//如果是 rootViewController 禁止滑動手勢
self.interactivePopGestureRecognizer.enabled = NO;
} else{
//如果不是 就啟用 滑動手勢
self.interactivePopGestureRecognizer.enabled = YES;
}
}
坑三:在視圖Push過程中,且Push尚未完成時觸發了Pop,可能會導致界面卡死,不響應任何手勢,點擊事件
解決方案:重寫 push方法
- (void) pushViewController:(UIViewController *)viewController animated:(BOOL)animated { self.interactivePopGestureRecognizer.enabled = NO; [super pushViewController:viewController animated:animated]; }
push時禁用了,push完就要開啟,否則手勢就無效了。開啟方法同坑二,實現UINavigationControllerDelegate 方法
- (void)navigationController:(UINavigationController *)navigationController didShowViewController:(UIViewController *)viewController animated:(BOOL)animated{ }
