UIPageViewController的翻页手势冲突问题。

如果用了自定义转场 或者其他的手势,并且还想用到PageViewController的手势翻页特效的话,那么手势冲突就不可避免了,目前用到的具体处理方法是重写UIPageViewController的手势接收方法。

首先,定义UIPageViewController为UIGestureRecognizerDelegate。

然后,在UIPageViewController中的ViewDidLoad里面遍历它的所有gestureRecgnizer:

for (UIGestureRecognizer *gesture in self.view.gestureRecognizers) {

gesture.delegate = self;

}

最后,重写手势判断方法:
由于这里面有两个手势判断器,所以可以根据需要来做判断
即:
 if ([gestureRecognizer isKindOfClass:[UIGestureRecognizer class]]) {

不过一般来讲,不用判断的话:

-(BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch {

CGPoint touchPoint = [touch locationInView:self.view];

if (touchPoint.x < self.view.frame.size.width * 0.75 && touchPoint.x > self.view.frame.size.width * 0.25 && touchPoint.y > self.view.frame.size.height * 0.2) {

return NO;

} else {

return YES;

}
这样做就够了。

评论

此博客中的热门博文

使__attribute__((annotate("xxx")))能作用于OC函数

viewWillAppear不执行的解决办法

iOS中使用xpc/xpc.h