當從控制器A push到控制器B,我們返回控制器A,除了使用按鈕返回
[self.navigationController pushViewController:Vc animated:YES];
還可以使用ios7出來的向右滑動,返回控制器A
文檔中是這樣定義的:
@property(nullable, nonatomic, weak) id<UINavigationControllerDelegate> delegate; @property(nullable, nonatomic, readonly) UIGestureRecognizer *interactivePopGestureRecognizer NS_AVAILABLE_IOS(7_0) __TVOS_PROHIBITED;
----------------------------------------------------------------------
我們在控制器B中的viewDidLoad中
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7.0) { self.navigationController.interactivePopGestureRecognizer.enabled = YES; // 手勢有效設置為YES 無效為NO self.navigationController.interactivePopGestureRecognizer.delegate = self; // 手勢的代理設置為self }
但是當回到控制器A中時,再想push到控制器B,就會出現卡屏,不會動的現象,因為rootView也會有向右滑動返回的問題
要解決這個問題,我們只需在控制器A的viewDidAppear中設置,interactivePopGestureRecognizer為NO:
-(void)viewDidAppear:(BOOL)animated { [super viewDidAppear:animated]; if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7.0) { self.navigationController.interactivePopGestureRecognizer.enabled = NO; } }
這樣即可以保證再B中向右滑返回A動后再次pushB時不會卡在A界面。