開發(fā)中偎快,出于某種需求或者避免某個(gè)bug冯乘,會(huì)有要求某一個(gè)界面不能側(cè)滑返回。這里給大家介紹一種簡(jiǎn)單的實(shí)現(xiàn)方法:
- 進(jìn)入該頁面時(shí)晒夹,關(guān)閉側(cè)滑手勢(shì):
- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
if([self.navigationController respondsToSelector:@selector(interactivePopGestureRecognizer)]) {
self.navigationController.interactivePopGestureRecognizer.enabled = NO;
}
}
- 進(jìn)入下個(gè)頁面或者返回上一個(gè)頁面時(shí)裆馒,啟用側(cè)滑手勢(shì):
- (void)viewWillDisappear:(BOOL)animated {
[super viewWillDisappear:animated];
if([self.navigationController respondsToSelector:@selector(interactivePopGestureRecognizer)]) {
self.navigationController.interactivePopGestureRecognizer.enabled = YES;
}
}
請(qǐng)看好方法分別是在哪個(gè)生命周期調(diào)用的,希望能幫到大家Xで印E绾谩!