当自定义一个navigationController实现全屏右划返回时, 使用起来是不是很爽, 代码如下:
- (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{
if (self.childViewControllers.count == 1 ) {
return NO;
}
return YES;
}
然鹅, 当你在tableView中打开左划编辑功能时发现死活也左划不了, 肿么肥四呢, 是打开姿势不对吗, MGD! 还是手势冲突呢?
好吧, 打个断点试试! 断点后发现进不来tableView的编辑方法, 进到了自定义的navigationController的gestureRecognizerShouldBegin方法, 原来是被拦截了. 那来判断一下是左划还是右划吧, 如果左划的话就不拦截, 交给tableView去响应! 代码如下:
- (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer{
if ([gestureRecognizer isKindOfClass:[UIPanGestureRecognizer class]]) { if (self.childViewControllers.count == ) {
return NO;
} if (self.interactivePopGestureRecognizer &&
[[self.interactivePopGestureRecognizer.view gestureRecognizers] containsObject:gestureRecognizer]) { CGPoint tPoint = [(UIPanGestureRecognizer *)gestureRecognizer translationInView:gestureRecognizer.view]; if (tPoint.x >= ) {
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;
}
貌似可以了! 欧耶!
可如果tableView也有右划呢......