記錄一次小問(wèn)題
蘋(píng)果在iOS7的UINavigationController中加入了一個(gè)返回手勢(shì)--interactivePopGestureRecognizer,因此支持iOS7以上版本,不用自己去實(shí)現(xiàn)一個(gè)手勢(shì)去操作.
在iOS開(kāi)發(fā)中,對(duì)于有些單獨(dú)的一個(gè)ViewController頁(yè)面等控制習(xí)慣性的喜歡在viewWillAppear生命周期方法中設(shè)置,因此在設(shè)置self.navigationController的interactivePopGestureRecognizer屬性禁用系統(tǒng)時(shí)也會(huì)這樣做.
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
self.navigationController.interactivePopGestureRecognizer.enabled = NO;
}
因?yàn)橹挥写藛为?dú)一個(gè)頁(yè)面禁用系統(tǒng)的手勢(shì)返回,所以要讓此ViewController自己去啟動(dòng)interactivePopGestureRecognizer. 在viewWillDisappear方法中去實(shí)現(xiàn)啟動(dòng)。
- (void)viewWillDisappear:(BOOL)animated
{
[super viewWillDisappear:animated];
self.navigationController.interactivePopGestureRecognizer.enabled = YES;
}
測(cè)試的時(shí)候,當(dāng)由ViewController通過(guò)push方法導(dǎo)航到下一個(gè)頁(yè)面,然后執(zhí)行手勢(shì)返回的時(shí)候會(huì)發(fā)生頁(yè)面卡住,但是按住Home鍵到后臺(tái),然后重新回到app確實(shí)可以返回到上一頁(yè)面.
通過(guò)操作檢查,當(dāng)我們開(kāi)始使用手勢(shì)返回的時(shí)候,在執(zhí)行interactivePopGestureRecognizer手勢(shì)方法action=handleNavigationTransition: 時(shí)就開(kāi)始執(zhí)行上一個(gè)頁(yè)面的viewWillAppear方法,而因此我在viewWillAppear方法中禁用了interactivePopGestureRecognizer返回手勢(shì),因此當(dāng)前頁(yè)面并沒(méi)有看到pop動(dòng)畫(huà),但確實(shí)是返回到上一頁(yè)面.由此修改內(nèi)容我們可以在viewDidAppear中,當(dāng)頁(yè)面已經(jīng)顯示的時(shí)候?qū)⒎椒ń?
- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
self.navigationController.interactivePopGestureRecognizer.enabled = NO;
}