ios - 将触摸事件从 UIScrollview 传递到 UICollectionView

标签 ios uiscrollview uigesturerecognizer uicollectionview uicollectionviewcell

我有一个使用自定义 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 的触摸...

传递触摸事件(单击/双击)的正确方法是什么?

最佳答案

关于ios - 将触摸事件从 UIScrollview 传递到 UICollectionView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19681654/

相关文章:

ios - 如何触发 Collection View 的 didSelectItemAtIndexPath : on tap while it's scrolling?

ios - UITableview 列表项问题

ios - 修改 iOS 项目的 RGB 值后尝试更新 UIImageView 时应用程序崩溃

iphone - 排列多个scrollView

ios - 是否建议在 iOS 应用程序中手动删除手势识别器

ios - 在画外音中注册 UIGestureRecognizer Action

iphone - 从 NSString 创建 NSDate

ios - 在 Apple 程序集中重复字节?

iphone - 如何使用计时器自动滚动 UIScrollView?

ios - 仅将滚动事件传递给被遮挡的 View