被覆盖的 UIControl 或 UIView 如何知道在其上方结束的触摸事件?

发布于 2024-08-02 08:01:08 字数 186 浏览 5 评论 0原文

我有一个 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

海风掠过北极光 2024-08-09 08:01:08

我认为有几种方法可以解决这个问题...

您可以将触摸事件传递给另一个控件...尽管我认为如果您将上方视图移动到另一个视图上,这不会起作用?你可能需要尝试一下。

更简单的方法可能只是查看下部矩形是否包含触摸点:

-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent*)event {
    UITouch *touch = [[event allTouches] anyObject];
    CGPoint touchLocation = [touch locationInView:self];
    if (CGRectContainsPoint(lowerView.frame, touchLocation)) {
        <doyourthing>
}

我不记得了,但您可能需要在两个视图之间转换视图坐标?!?或者您可以使用 - (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:

-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent*)event {
    UITouch *touch = [[event allTouches] anyObject];
    CGPoint touchLocation = [touch locationInView:self];
    if (CGRectContainsPoint(lowerView.frame, touchLocation)) {
        <doyourthing>
}

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文