UIViewクラスでconvertPoint:toView:
メソッドを使用することができますself.viewすることtapPoint
を変換するにはUITapGestureRecognizer
UITapGestureRecognizer *tapRecognizer = [[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapAction:)] autorelease];
[myScrollView addGestureRecognizer:tapRecognizer];
- (void)tapAction:(UITapGestureRecognizer*)sender{
CGPoint tapPoint = [sender locationInView:myScrollView];
CGPoint tapPointInView = [myScrollView convertPoint:tapPoint toView:self.view];
}
を使用して検出します。次の問題は、イベントがスクロールビューに送信されるため、-(void)touchesBegan:touches:event
が呼び出されないことです。これは、UIScrollViewをサブクラス化して、スクロールビューがタッチイベントを次のレスポンダ(ビュー)に送信するように修正できます。
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
// Position of touch in view
UITouch *touch = [[event allTouches] anyObject];
CGPoint touchPoint = [touch locationInView:self.view];
// Scroll view offset
CGPoint offset = scrollView.contentOffset;
// Result
CGPoint scrollViewPoint = CGPointMake(touchPoint.x, touchPoint.y + offset.y);
NSLog(@"Touch position in scroll view: %f %f", scrollViewPoint.x, scrollViewPoint.y);
}
タップしてスクロールしないと、tapActionが起動されます。私が好きなら、タップ、スクロール、指を持ち上げたり、タップしたり、スクロールしたり、指を持ち上げたりするなど、タップは検出されません。スクロールが大きなスワイプの後にスクロールしている場合も、タップは検出されません。スクロールバーは静止していなければならず、1つのドライタップを作成しなければなりません。 – SpaceDog
他の多くのジェスチャー認識 - UIPanGestureRecognizer、UIPinchGestureRecognizer、UISwipeGestureRecognizer、UIRotationGestureRecognizerがあります。さらに、カスタムレコグナイザを作成して、非常に複雑なタッチを検出することもできます。私はシンプルなタッチでより一般的な例を与えました。 – beryllium
@RubberDuckあなたはこれを理解しましたか?私は同じボートに乗っています...私はUICollectionViewで作業しています。指のタッチがセルビュー上にあるかどうかを検出したい場合は –