1、理解NavigationController返回机制
一般NavigationController下的子view只有一层或者有很多层,子view返回最顶层则可以直接用
[self.navigationController popViewControllerAnimated:YES];
如果NavigationController下有好几层子view,当前子view返回上一层,则可以用
[self.navigationController popToViewController:[self.navigationController.viewControllers objectAtIndex:([self.navigationController.viewControllers count] -2)] animated:YES];
-3为上上一层,依此类推。push和pop的方法类似。
2、手势右滑返回上一层
控制器添加代理UIGestureRecognizerDelegate
self.navigationController.interactivePopGestureRecognizer.delegate = self; - (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer{ //判断是否是导航条的第一个子视图控制器 if (self.navigationController && [self.navigationController.viewControllers count] >= 2) { return YES; }else{ return NO; } }
模态、导航栏混合模式
https://www.cnblogs.com/dingding3w/p/6222626.html