按钮上方的活动指示器阻止点击识别
我有一个 UIButton“bn”和一个位于按钮上方的 UIActivityIndicator“ai”(ai.center = bn.center
)。
只要 ai 可见且有动画,我就无法按下 ai 框架下方的按钮,但超出了我可以按下的范围。
我是否必须将 GestureRecognition 添加到 ai 中,或者是否有更智能的方法来单击“ai”。
亲切的问候。 $h@rky
I have an UIButton "bn" and an UIActivityIndicator "ai" which is above the button (ai.center = bn.center
).
As long as ai is visible and animating, I can't press the Button underneath ai's frame but out of the range I can.
Do I have to add GestureRecognition to ai or is there a smarter way to click on the "ai".
Kind regards. $h@rky
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以简单地设置
ai.userInteractionEnabled = NO;
吗?我很惊讶它无论如何都在活动指示器上启用 - 这是一个标准组件还是您创建了一个子类?顺便说一句,拥有一个被另一个视图覆盖的交互元素通常是糟糕的 UI 设计,特别是用于指示某些内容“忙碌”的视图,但在可点击缩略图的示例中,它似乎使感觉。
Can you simply set
ai.userInteractionEnabled = NO;
? I'm surprised it is enabled anyway, on an activity indicator - is this a standard component or have you made a subclass?As an aside, it is usually poor UI design to have an interactive element that is covered by another view, particularly one which is used to indicate that something is "busy", but in your example of a clickable thumbnail image, it seems to make sense.
您需要
在父视图中重写 UIView 方法。如果点击在按钮内,则返回按钮,否则返回 nil。这是关于此方法的讨论的一部分:
编辑:
假设你有一个包含 bn 和 ai 的 UIView 子类,你可以实现这样的方法
,这样你的按钮将获得触摸事件(如果它们在其框架内),无论是否有东西在它上面。您不需要做任何其他事情。
You need to override the UIView method
in the parent view. If the hit is within the button the you return the button, else you return nil. This is part of the the discussion on this method:
EDIT:
Say you have a UIView subclass which contains bn and ai, you can implement the method like this
that way your button will get the touch events (if they are within its frame) no matter if something is on top of it or not. You do not need to do anything else.
使用以下内容:
首先,使用以下方法重写为 UIActivityIndicator 创建子类:
之后,在项目中的所有位置使用 MyActivityIndicator 而不是 UIActivityIndicator (在 NIB 文件或代码中,取决于您在何处创建它)
Use the following stuff:
First, create subclass for UIActivityIndicator with the following method override:
After that, use MyActivityIndicator everywhere in your project instead of UIActivityIndicator (in NIB file or in your code, depends where do you create it)