collectionView手势与其它控件事件冲突问题

2018-08-20  本文已影响0人  李琪_59dc

解决办法

1,遵守协议UIGestureRecognizerDelegate
2,给外层View添加手势,设置代理

UITapGestureRecognizer *tapGestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(didClickView)]; 
tapGestureRecognizer.delegate = self;  
 [self.collectionview addGestureRecognizer:tapGestureRecognizer];

3,利用手势的代理方法进行判断,如果手势执行的视图不是需要的视图就不让其执行(这时点击item就会响应自身的方法)
主要用到的协议方法是shouldReceiveTouch

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch {
        if ([NSStringFromClass([touch.view class]) isEqualToString:@"_UITableViewHeaderFooterContentView"]) {
        return YES;
    }
    return NO;
}
上一篇 下一篇

猜你喜欢

热点阅读