iPhone - UIScrollView...检测触摸的坐标
可能的重复:
UIScrollview获取触摸事件
是否可以检测手指触摸 UIScrollView 中的位置?
我的意思是,假设用户以这种方式使用他的手指:点击并滚动,再次抬起手指,点击并滚动等。是否有可能知道相对于 self.view 滚动条发生点击的 CGPoint在?滚动条占据了整个 self.view。
谢谢。
Possible Duplicate:
UIScrollview getting touch events
Is it possible to detect where in a UIScrollView the finger touched?
I mean, suppose the user uses his finger in this way: taps and scroll, lifts the finger and again, taps and scroll, etc. Is it possible to know the CGPoint where the taps happened in relation to the self.view the scroller is in? The scroller occupies the whole self.view.
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您可以使用手势识别器来做到这一点。要检测单击位置,请使用
UITapGestureRecognizer
要将
tapPoint
转换为 self.view,您可以使用convertPoint:toView:
方法You can do it with gesture recognizers. For detect single tap location use
UITapGestureRecognizer
To convert that
tapPoint
to self.view you can useconvertPoint:toView:
method in UIView class看看 touchesBegan:withEvent: 你会得到一个 UITouch 的 < /a>,并且 UITouch 包含一个 locationInView: 方法,该方法应返回触摸的 CGPoint。
Take a look at touchesBegan:withEvent: You will get a NSSet of UITouch's, and a UITouch contains a locationInView: method that should return the CGPoint of the touch.
您可能能够将其子类化并查看 TouchesBegan。
http://developer.apple.com/library/ios/documentation/UIKit/Reference/UIResponder_Class/Reference/Reference.html#//apple_ref/doc/uid/TP40006783-CH4-SW1
You'd probably be able to subclass it and look at touchesBegan.
http://developer.apple.com/library/ios/documentation/UIKit/Reference/UIResponder_Class/Reference/Reference.html#//apple_ref/doc/uid/TP40006783-CH4-SW1
您可以在视图中找到该位置并向其添加滚动偏移。现在,您的下一个问题是
-(void)touchesBegan:touches:event
将不会被调用,因为事件将发送到您的滚动视图。这可以通过对 UIScrollView 进行子类化并让滚动视图将触摸事件发送到下一个响应者(您的视图)来解决。You could find the location in the view and add the scroll ofset to it. Now, your next problem is that
-(void)touchesBegan:touches:event
won't be called because the events will be sent to your scrollview. This can be fixed by subclassing your UIScrollView and have the scrollview send the touch events to the next responder (your view).