允许与另一个 UIView 下的 UIView 交互 [英] Allowing interaction with a UIView under another UIView

查看:25
本文介绍了允许与另一个 UIView 下的 UIView 交互的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有一种简单的方法可以允许与位于另一个 UIView 下的 UIView 中的按钮进行交互 - 按钮顶部的顶部 UIView 没有实际对象?

Is there a simple way of allowing interaction with a button in a UIView that lies under another UIView - where there are no actual objects from the top UIView on top of the button?

例如,目前我有一个 UIView (A),顶部有一个对象,屏幕底部有一个对象,中间什么也没有.它位于另一个 UIView 之上,中间有按钮 (B).但是,我似乎无法与 B 中间的按钮进行交互.

For instance, at the moment I have a UIView (A) with an object at the top and an object at the bottom of the screen and nothing in the middle. This sits on top of another UIView that has buttons in the middle (B). However, I cannot seem to interact with the buttons in the middle of B.

我可以看到 B 中的按钮 - 我已将 A 的背景设置为 clearColor - 但 B 中的按钮似乎没有收到触摸,尽管实际上这些按钮顶部没有来自 A 的对象.

I can see the buttons in B - I've set the background of A to clearColor - but the buttons in B do not seem to receive touches despite the fact that there are no objects from A actually on top of those buttons.

EDIT - 我仍然希望能够与顶部 UIView 中的对象进行交互

EDIT - I still want to be able to interact with the objects in the top UIView

当然有一种简单的方法可以做到这一点吗?

Surely there is a simple way of doing this?

推荐答案

你应该为你的顶视图创建一个 UIView 子类并覆盖以下方法:

You should create a UIView subclass for your top view and override the following method:

- (BOOL)pointInside:(CGPoint)point withEvent:(UIEvent *)event {
    // UIView will be "transparent" for touch events if we return NO
    return (point.y < MIDDLE_Y1 || point.y > MIDDLE_Y2);
}

您还可以查看 hitTest:event: 方法.

You may also look at the hitTest:event: method.

这篇关于允许与另一个 UIView 下的 UIView 交互的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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