UITextViewを含むUICollectionViewCellsを持つ水平スクロールUICollectionViewがあります。didSelectItemAtIndexPath が呼び出されるように、テキストビューのジェスチャをセルに渡す方法はありますか? UITextView をサブクラス化し、 touchesbegin/end をセルに渡して試しましたが、うまくいきませんでした。
2164 次
3 に答える
6
ビューを非インタラクティブにすることができます。これにより、タッチが通過します。
textView.userInteractionEnabled = NO;
インタラクティブにする必要がある場合は、これを試すことができます:
textView.editable = NO;
UITapGestureRecognizer* tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapped)];
[textView addGestureRecognizer:tap];
...そして、この関数をUICollectionViewCell
サブクラスに追加します。
-(void) tapped {
UICollectionView *collectionView = (UICollectionView*)self.superview;
NSIndexPath *indexPath = [collectionView indexPathForCell:self];
[collectionView.delegate collectionView:collectionView didSelectItemAtIndexPath:indexPath];
}
私はそれをテストしていませんが...
于 2013-03-28T13:08:39.510 に答える
0
これは iOS6.x では機能しないようです: UICollectionViewCell のすべてのビューは、セルの最初の子である UIView に埋め込まれているようです。UITextView が入っている実際のセルを取得するには、もう一度逆参照する必要があります。つまり、順序は次のとおりです (下から上へ)。
UITextView->enclosingUIView->UICollectionViewCell
于 2013-08-12T04:20:48.507 に答える
0
セルがテキスト ビューのスーパービューである場合、UITextViewDelegate
メソッドで次のようなものを実装できますtextViewDidBeginEditing:
。
- (void)textViewDidBeginEditing:(UITextView *)textView {
NSIndexPath *indexPath = [self.collectionView indexPathForCell:(UICollectionViewCell *)textView.superview];
[self.collectionView selectItemAtIndexPath:indexPath animated:YES scrollPosition:UICollectionViewScrollPositionTop];
}
于 2013-03-28T12:31:44.200 に答える