被覆盖的 UIControl 或 UIView 如何知道在其上方结束的触摸事件?
我有一个 UIControl(或 UIView,无论哪个),并且它被另一个 UIControl 覆盖。另一个 UIControl 对触摸事件反应良好。然而,底层 UIControl 还需要了解触摸,以及从用户的角度来看触摸是否确实“在其上”。覆盖的 UIControl 是部分透明的。
我怎样才能捕捉到底层 UIControl 上的这种触摸?
I have a UIControl (or UIView, doesn't matter which) and this is covered by another UIControl. The other UIControl reacts nicely on touch events. However, the underlying UIControl also needs to know about the touch and if it was actually "on it" or not from the user's perspective. The covering UIControl is partially transparent.
How can I catch this touch on the underlying UIControl?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为有几种方法可以解决这个问题...
您可以将触摸事件传递给另一个控件...尽管我认为如果您将上方视图移动到另一个视图上,这不会起作用?你可能需要尝试一下。
更简单的方法可能只是查看下部矩形是否包含触摸点:
我不记得了,但您可能需要在两个视图之间转换视图坐标?!?或者您可以使用 - (BOOL)pointInside:(CGPoint)point withEvent:(UIEvent *)event 询问视图本身
I think there are couple ways you could go about this...
You could pass the touch event on to the other control...though i don't think that'll work if you're moving the upper view over the other view? You might have to experiment.
The easier way might be just to see if the lower rect contains the touch point:
I don't recall offhand but you may need to convert the view coordinates between the two views?!? or you could ask the view itself with - (BOOL)pointInside:(CGPoint)point withEvent:(UIEvent *)event