1.bug 描述:通過(guò) UINavigationController push 出一個(gè)新頁(yè)面, 但是頁(yè)面被 push 之后是透明的, 沒(méi)有顯示任何 UI, 就導(dǎo)致當(dāng)前 Controller 上面有一個(gè)透明的層, 點(diǎn)擊當(dāng)前頁(yè)面就沒(méi)有任何反應(yīng), 但是通過(guò) Xcode 自帶的Debug view Hierarchy可以看到新頁(yè)面已經(jīng)push, 但是手機(jī)上并沒(méi)有顯示
可能是我敘述的不夠清楚, 不是沒(méi)有設(shè)背景色, 頁(yè)面是是有 UI 的, 平時(shí)都沒(méi)問(wèn)題, push 之后 UI 就顯示了, 然后拉接口刷新頁(yè)面, 偶爾會(huì)出現(xiàn)這種情況, 點(diǎn)擊 push 之后代碼執(zhí)行了, 頁(yè)面也 push 了, 但是手機(jī)上沒(méi)有顯示, 只能用Debug view Hierarchy才能看到
2.觸發(fā) bug:只要在 rootview 右滑幾次,點(diǎn)擊 push 界面就會(huì)出現(xiàn)這個(gè)問(wèn)題
3.解決方法是:
OC:
在 導(dǎo)航控制的根控制器(baseViewController) 中,實(shí)現(xiàn)代理:UIGestureRecognizerDelegate
在 viewdidload 方法中寫:
self.navigationController.interactivePopGestureRecognizer.delegate = self;
然后實(shí)現(xiàn)下面的方法:
- (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer*)gestureRecognizer {
? ? if([self.navigationController respondsToSelector:@selector(interactivePopGestureRecognizer)]
? ? ? ? && gestureRecognizer ==self.navigationController.interactivePopGestureRecognizer
? ? ? ? &&self.navigationController.visibleViewController == [self.navigationController.viewControllers objectAtIndex:0]) {
? ? ? ? NSLog(@"Gesture blocked===手勢(shì)鎖定");
? ? ? ? returnNO;
? ? }
? ? NSLog(@"Gesture begin===手勢(shì)開啟");
? ? return YES;
}
swift:同理
在 viewdidload:
navigationController?.interactivePopGestureRecognizer?.delegate = self
實(shí)現(xiàn)下面的方法:
?//解決執(zhí)行了 push 之后,push 不出界面的 bug,要在 rootview 中實(shí)現(xiàn)這個(gè)方法
? ? func gestureRecognizerShouldBegin(_ gestureRecognizer:UIGestureRecognizer) ->Bool{
//? ? ? ? navigationController?.responds(to: #selector(interactivePopGestureRecognizer)) &&
? ? ? ? if (gestureRecognizer == self.navigationController?.interactivePopGestureRecognizer) && (self.navigationController?.visibleViewController == self.navigationController?.viewControllers.first) {
? ? ? ? ? ? return false
? ? ? ? }
? ? ? ? return true
? ? }