如何将手势从 UITextView 传递到 UICollectionViewCell [英] How to pass gestures from UITextView to UICollectionViewCell
问题描述
我有一个带有 UICollectionViewCells 的水平滚动 UICollectionView,其中包含一个 UITextView.有没有办法将 textview 上的手势传递给单元格,以便调用 didSelectItemAtIndexPath?.我尝试将 UITextView 子类化并将 touchesbegin/end 传递给单元格,但这没有用.
I have a horizontal scrolling UICollectionView with UICollectionViewCells that contain a UITextView. Is there any way to pass gestures on the textview to the cells, so that didSelectItemAtIndexPath gets called?. I tried it with subclassing UITextView and passing touchesbegin/end to the cell, but that didn't worked.
推荐答案
您可以使视图非交互式,这将导致触摸通过:
You can make the view non-interactive, which will cause touches to get passed through:
textView.userInteractionEnabled = NO;
如果你需要它是互动的,你可以试试这个:
If you need it to be interactive, you can try this:
textView.editable = NO;
UITapGestureRecognizer* tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapped)];
[textView addGestureRecognizer:tap];
... 然后将此函数添加到您的 UICollectionViewCell
子类:
... and then add this function to your UICollectionViewCell
subclass:
-(void) tapped {
UICollectionView *collectionView = (UICollectionView*)self.superview;
NSIndexPath *indexPath = [collectionView indexPathForCell:self];
[collectionView.delegate collectionView:collectionView didSelectItemAtIndexPath:indexPath];
}
我还没有测试过...
这篇关于如何将手势从 UITextView 传递到 UICollectionViewCell的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!