简体   繁体   English

如何通过UICollectionView捕获手势?

[英]How can I catch the gestures over UICollectionView?

I have a UICollectionView and a custom UICollectionViewCell 我有一个UICollectionView和一个自定义UICollectionViewCell

I want to be able to catch the UICollectionView gestures as a UIGestureRecognizerDelegate , actually I want to handle some gestures collisions by using this delegate's method: 我希望能够将UICollectionView手势捕获为UIGestureRecognizerDelegate ,实际上我想通过使用此委托的方法来处理一些手势冲突:

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer

How can I catch the UICollectionView 's UIGestureRecognizerDelegate ? 如何捕获UICollectionViewUIGestureRecognizerDelegate

UICollectionView does listen for taps but not by using a UIGestureRecognizer . UICollectionView会侦听点击,但不会使用UIGestureRecognizer

But you could add your own UIGestureRecognizer for the type your interested in (like UITapGestureRecognizer for instance) to the UICollectionView , set the delegate on it and in gestureRecognizerShouldBegin: return YES or NO depending on whether you want the UICollectionView to do it's thing or not, ie returning NO would cancel your gesture and allow the collection view to handle the touches. 但是你可以为你感兴趣的类型添加你自己的UIGestureRecognizer (例如UITapGestureRecognizer )到UICollectionView ,在它UICollectionView设置委托,在gestureRecognizerShouldBegin:返回YES或NO,这取决于你是否希望UICollectionView这样做,即返回NO将取消您的手势并允许集合视图处理触摸。

Or set delayTouchesBegan to YES if you just want your gestures to take priority over the collection view touch handling. 或者,如果您只是希望手势优先于集合视图触摸处理,请将delayTouchesBegan设置为YES。

More info is here Collection View Programming Guide 更多信息在这里收集视图编程指南

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 iOS Swift手势:如何用手势链接两个项目 - iOS Swift Gestures : How can I link two items with gestures 如何在ios模拟器中禁用手势? - How can I disable gestures in the ios simulator? 如何在 ios 中覆盖 VoiceOver 手势? - How can I override VoiceOver gestures in ios? 如何将UICollectionViewCell从一个UICollectionView拖到另一个UICollectionView? - How can I drag a UICollectionViewCell from one UICollectionView to another UICollectionView? 如何识别Apple Watch应用程序中的手势? - How can I recognise gestures in an Apple Watch app? 如何禁用UITableView上的左右滑动手势 - How can I disable left and right swipe gestures on a UITableView 如何在 SwiftUI 中组合 3 个不同的同时手势? - How can I compose 3 different, simultaneous gestures in SwiftUI? 在 SwiftUI 中,我怎样才能执行手势但向前手势到它后面的视图? - In SwiftUI, how can I perform a gesture but forward gestures to the view behind it? 如何设置UIPageViewController(分页类型)手势委托 - How can I set UIPageViewController (Paging Type) gestures delegate 如何在iOS手势中禁用“弹弓”动作? - How can I disable “slingshot” action in iOS gestures?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM