我有一个使用自定义 UICollectionViewCell 的 UICollectionView,它又包含包含 UIImageView 的 UIScrollView。
UIScrollView 有几个附加到它的手势识别器(点击,双击)。我使用 UIScrollView 来放大图像。
问题是我能够在 UICollectionView 中接收触摸事件的唯一方法是禁用 UIScrollView 中的用户交互。尽管如此,UICollectionView 仍在滚动,所以显然 UIScrollView 上的一些手势正在传递给父 UICollectionView)
我通过在 UIScrollView(自定义类)中添加这些方法尝试了另一种解决方案
@interface MyScrollView : UIScrollView
@end
@implentation MyScrollView
-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
[[self nextResponder] touchesEnded:touches withEvent:event];
}
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
[[self nextResponder] touchesBegan:touches withEvent:event];
}
-(void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event
{
[[self nextResponder] touchesCancelled:touches withEvent:event];
}
-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
[[self nextResponder] touchesMoved:touches withEvent:event];
}
@end
这有助于让 collectionview 接收触摸,但是当在 scrollview 中向上滑动时,collectionview 将停止接收 future 的触摸...
传递触摸事件(单击/双击)的正确方法是什么?
最佳答案
你实现了吗gestureRecognizer:shouldRecognizeSimultaneouslyWithGestureRecognizer: ?
参见此处:Multiple Gestures for UIGestureRecognizers (iPhone, Cocos2d)
关于ios - 将触摸事件从 UIScrollview 传递到 UICollectionView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19681654/