iOS push側(cè)滑返回功能實現(xiàn)方法
更新時間:2018年05月11日 16:15:34 作者:jingwei卍
這篇文章主要為大家詳細介紹了iOS push側(cè)滑返回功能實現(xiàn)方法,具有一定的參考價值,感興趣的小伙伴們可以參考一下
本文實例為大家分享了iOS push側(cè)滑返回功能的具體代碼,供大家參考,具體內(nèi)容如下
開啟iOS自帶的push的側(cè)滑返回功能(只有左側(cè)邊緣地帶響應(yīng)側(cè)滑返回,并不是全局響應(yīng)):
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7.0) {
[self.navigationController.interactivePopGestureRecognizer setEnabled:YES];
self.navigationController.interactivePopGestureRecognizer.delegate = self;
}
}
為防止導(dǎo)航控制器在根視圖時觸發(fā)手勢
- (BOOL)gestureRecognizerShouldBegin:(UIPanGestureRecognizer *)gestureRecognizer {
if (self.childViewControllers.count == 1) {
return NO;
} else {
return YES;
}
}
這樣 在根視圖側(cè)滑返回操作,然后出發(fā)push會沒有效果,界面會卡住;代碼已經(jīng)push到下一個VC,但界面還停留在根視圖。
解決方法是在根視圖添加如下代碼:
-(void)viewDidAppear:(BOOL)animated{
[super viewDidAppear:animated];
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7.0) {
self.navigationController.interactivePopGestureRecognizer.enabled = NO;
}
}
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

