Collection view

collection view 2 - Incorporatin

2017-03-25  本文已影响5人  轻云绿原

来源:https://developer.apple.com/library/content/documentation/WindowsViews/Conceptual/CollectionViewPGforIOS/IncorporatingGestureSupport/IncorporatingGestureSupport.html

Incorporating Gesture Support

重点:你应该对collection view加手势,而不是一个具体的cell或view.

collectionview 对单点手势已经有delegate去监听了。所以,你只能加双击手势或其它非单击手势。

下面的代码,展示了怎么让collection view 响应您的双击手势而不是响应delegate里的选择/高亮手势。

UITapGestureRecognizer* tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleTapGesture:)];

tapGesture.delaysTouchesBegan = YES;

tapGesture.numberOfTapsRequired = 2;

[self.collectionView addGestureRecognizer:tapGesture];

你可以通过设置delaysTouchesBegancancelsTouchesInView属性 true,来让您的手势的优先级别高于默认选择监听者。当手势注册了,你首先会查看你的手势是否有优先级。只有当输入对你的手势无效时,那里delegate的方法才会像平时一样会调用。

上一篇下一篇

猜你喜欢

热点阅读