當自定義一個navigationController實現全屏右劃返回時, 使用起來是否是很爽, 代碼以下:spa
- (void)viewDidLoad { [super viewDidLoad]; UIGestureRecognizer *gester = self.interactivePopGestureRecognizer;
UIPanGestureRecognizer *panGesTer = [[UIPanGestureRecognizer alloc] initWithTarget:gester.delegate action:NSSelectorFromString(@"handleNavigationTransition:")];
[gester.view addGestureRecognizer:panGesTer];
gester.delaysTouchesBegan = YES;
panGesTer.delegate = self; }
-(BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer{code
if (self.childViewControllers.count == 1 ) {
return NO;blog
}事件
return YES;get
}it
然鵝, 當你在tableView中打開左劃編輯功能時發現死活也左劃不了, 腫麼肥四呢, 是打開姿式不對嗎, MGD! 仍是手勢衝突呢? io
好吧, 打個斷點試試! 斷點後發現進不來tableView的編輯方法, 進到了自定義的navigationController的gestureRecognizerShouldBegin方法, 原來是被攔截了. 那來判斷一下是左劃仍是右劃吧, 若是左劃的話就不攔截, 交給tableView去響應! 代碼以下:table
- (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer{ if ([gestureRecognizer isKindOfClass:[UIPanGestureRecognizer class]]) { if (self.childViewControllers.count == 1 ) { return NO; } if (self.interactivePopGestureRecognizer && [[self.interactivePopGestureRecognizer.view gestureRecognizers] containsObject:gestureRecognizer]) { CGPoint tPoint = [(UIPanGestureRecognizer *)gestureRecognizer translationInView:gestureRecognizer.view]; if (tPoint.x >= 0) { CGFloat y = fabs(tPoint.y); CGFloat x = fabs(tPoint.x); CGFloat af = 30.0f/180.0f * M_PI; CGFloat tf = tanf(af); if ((y/x) <= tf) { return YES; } return NO; }else{ return NO; } } } return YES; }
貌似能夠了! 歐耶!class
可若是tableView也有右劃呢......原理