通过 UITapGestureRecognizer 获取 UIScrollView 中的接触点 [英] Get touch points in UIScrollView through UITapGestureRecognizer

查看:28
本文介绍了通过 UITapGestureRecognizer 获取 UIScrollView 中的接触点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 UIScrollview 和 UITapGestureRecognizer 来获取触摸事件.

i am using UIScrollview and UITapGestureRecognizer for getting touch event.

现在,我想要触摸位置的 x 和 y 坐标.

Now, i want x and y coordinates for my touch position.

有什么帮助吗?

推荐答案

在你的手势识别处理程序中:

In your gesture recognizer handler:

 CGPoint location = [gestureRecognizer locationInView:gestureRecognizer.view];

如果需要,您可以指定不同的视图.

you could specify a different view, if you need it.

或者你也可以使用这个它属于 View 而不是 ViewController,看起来像这样:

or u can use this also It belongs in a View rather than ViewController, and would look something like this:

-(void)touchesBegan:(NSSet*)touches withEvent:(UIEvent*)evt {
  UITouch *touch=[touches anyObject];
  CGPoint pt=[touch locationInView:self];
  // ...make your button at 'pt'...
}

这篇关于通过 UITapGestureRecognizer 获取 UIScrollView 中的接触点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆