星空网 > 软件开发 > 操作系统

拖拽手势和清扫手势冲突时(UIPanGestureRecognizer和UISwipeGestureRecognizer冲突时)

  故事发生在这样的情境上:给整个控制器添加了一个拖拽手势,然后又在控制上的每个Cell上加了左滑清扫手势,然后问题来了:只有拖拽手势起作用,而左滑手势没有效果了,然后怎么解决这个问题呢!先上图:

拖拽手势和清扫手势冲突时(UIPanGestureRecognizer和UISwipeGestureRecognizer冲突时)images/loading.gif' data-original="http://images2015.cnblogs.com/blog/454511/201604/454511-20160403084331957-1426330955.gif" />

当给整个控制器添加了拖拽手势(UIPanGestureRecognizer),然后在控制器里面的UITableViewCell又添加了左滑清扫手势(UISwipeGestureRecognizer),造成了只有拖拽手势起了作用,而Cell的左滑手势已经不能滑动了!

解决办法就是给这两个手势设置一个优先级:[panGes requireGestureRecognizerToFail:cell.leftSwipe];

关键代码

 1 + (instancetype)cellWithTableView:(UITableView *)tableView{ 2   static NSString *reuseIdentity = @"tanCell"; 3    4   TanTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:reuseIdentity]; 5    6   if (cell == nil){ 7     cell = [[TanTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:reuseIdentity]; 8      9     //设置手势优先级,避免手势冲突10     UIPanGestureRecognizer *panGes = [tableView.superview.gestureRecognizers objectAtIndex:0];11     [panGes requireGestureRecognizerToFail:cell.leftSwipe];12     [panGes requireGestureRecognizerToFail:cell.rightSwipe];13   }14   return cell;15 }

至于如何给Cell设置左滑多菜单功能手势,见拙文:自定义UITableViewCell实现左滑动多菜单功能LeftSwipe

 

DEMO下载:

github: https://github.com/xiaotanit/Tan_SwipeAndPan

 

原文链接:http://www.cnblogs.com/tandaxia/p/5349090.html




原标题:拖拽手势和清扫手势冲突时(UIPanGestureRecognizer和UISwipeGestureRecognizer冲突时)

关键词:ip

ip
*特别声明:以上内容来自于网络收集,著作权属原作者所有,如有侵权,请联系我们: admin#shaoqun.com (#换成@)。

加拿大的标志性建筑物是什么:https://www.goluckyvip.com/tag/56029.html
促销引流大招:https://www.goluckyvip.com/tag/5603.html
加拿大的建筑物标志图片:https://www.goluckyvip.com/tag/56030.html
加拿大标志性建筑物图片:https://www.goluckyvip.com/tag/56031.html
FBA退货问题:https://www.goluckyvip.com/tag/5604.html
英国大学校徽:https://www.goluckyvip.com/tag/56040.html
23点聊电商:新质生产力加速数字贸易发展 卓尔智联集团实现营收利润双增长 :https://www.kjdsnews.com/a/1836411.html
南京浦口都有什么好玩的地方 南京浦口都有什么好玩的地方推荐:https://www.vstour.cn/a/363180.html
相关文章
我的浏览记录
最新相关资讯
海外公司注册 | 跨境电商服务平台 | 深圳旅行社 | 东南亚物流