关于UIPageViewController去除边缘点击手势

 

如果page上方还有一层UI控件的话,不去除边缘点击手势会造成手势的冲突干扰。

首先我做的处理是设置pageView的手势代理

for (UIGestureRecognizer *gr in _pageViewController.gestureRecognizers) {

         if ([gr isKindOfClass:[UIPanGestureRecognizer class]]) {

               gr.delegate = self;
         }
}
-(BOOL) gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch    (UITouch *)touch {
    if ([gestureRecognizer isKindOfClass:[UITapGestureRecognizer class]]) {
            return NO;
         }
    return YES;  
}

 但是这样处理,会在第一页忘前翻页和在最后一页往后翻页出现crash,而且不清楚原因。

正确处理方法:

新建一个UIpageControlller的类别

#import <UIKit/UIKit.h>

@interface UIPageViewController (YCGestureTool)

@end

 

#import "UIPageViewController+YCGestureTool.h"

@implementation UIPageViewController (YCGestureTool)

-(BOOL) gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch{
    if ([gestureRecognizer isKindOfClass:[UITapGestureRecognizer class]]) {
        return NO;
    }
    return YES;
}

 完美解决!

 

posted @ 2018-08-08 18:38  小师傅啊小师傅  阅读(786)  评论(0编辑  收藏  举报