时间:2021-04-23 09:29:00 | 栏目:iOS代码 | 点击:次
本文实例为大家分享了iOS push侧滑返回功能的具体代码,供大家参考,具体内容如下
开启iOS自带的push的侧滑返回功能(只有左侧边缘地带响应侧滑返回,并不是全局响应):
- (void)viewWillAppear:(BOOL)animated { [super viewWillAppear:animated]; if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7.0) { [self.navigationController.interactivePopGestureRecognizer setEnabled:YES]; self.navigationController.interactivePopGestureRecognizer.delegate = self; } }
为防止导航控制器在根视图时触发手势
- (BOOL)gestureRecognizerShouldBegin:(UIPanGestureRecognizer *)gestureRecognizer { if (self.childViewControllers.count == 1) { return NO; } else { return YES; } }
这样 在根视图侧滑返回操作,然后出发push会没有效果,界面会卡住;代码已经push到下一个VC,但界面还停留在根视图。
解决方法是在根视图添加如下代码:
-(void)viewDidAppear:(BOOL)animated{ [super viewDidAppear:animated]; if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7.0) { self.navigationController.interactivePopGestureRecognizer.enabled = NO; } }