起因:
之前一直沒(méi)有遇到類(lèi)似問(wèn)題,最近遇到項(xiàng)目UI視圖經(jīng)常卡死現(xiàn)象,一直沒(méi)找到必現(xiàn)條件,后面發(fā)現(xiàn)在rootViewController頁(yè)面觸發(fā)側(cè)滑返回pop操作,再push就會(huì)卡死,定位到是側(cè)滑手勢(shì)導(dǎo)致的。
分析:
因?yàn)槲覀兊膎avigationController是自定義的,所以系統(tǒng)的側(cè)滑返回手勢(shì)會(huì)被禁掉,項(xiàng)目需要我們執(zhí)行以下代碼,把側(cè)滑手勢(shì)打開(kāi)
@implementation DDNavigationController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
__weak typeof(self) weakself = self;
if ([self respondsToSelector:@selector(interactivePopGestureRecognizer)]) {
self.interactivePopGestureRecognizer.delegate = (id)weakself;
}
}
@end
此時(shí),如果我們?cè)趓ootViewController里面執(zhí)行側(cè)滑手勢(shì),相當(dāng)于執(zhí)行了一個(gè)pop操作(只是我們沒(méi)有看到效果),然后接著再去執(zhí)行push,自然就push不到下一級(jí)頁(yè)面了。
解決方法:
判斷當(dāng)前頁(yè)面是不是根視圖,如果是就禁止掉側(cè)滑返回手勢(shì),如果不是就打開(kāi),代碼如下(在DDNavigationController中實(shí)現(xiàn)):
#pragma mark - UIGestureRecognizerDelegate
- (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer {
if (gestureRecognizer == self.interactivePopGestureRecognizer) {
// 屏蔽調(diào)用rootViewController的滑動(dòng)返回手勢(shì)
if (self.viewControllers.count < 2 || self.visibleViewController == [self.viewControllers objectAtIndex:0]) {
return NO;
}
}
return YES;
}
。