gpt4 book ai didi

swift - 当按钮覆盖在 tableview 顶部时,如何防止 tableview 单元格注册点击?

转载 作者:行者123 更新时间:2023-11-28 13:43:59 25 4
gpt4 key购买 nike

我的应用程序有一个标签栏,我在标签栏的中央添加了一个大按钮。为此,我只需创建一个按钮并将其作为 subview 添加到选项卡栏。

按钮的顶部越过标签栏的顶部边缘,位于 tableview 的顶部。这是屏幕截图。

enter image description here

当我点击按钮的底部(绿色箭头)时,它工作正常,但如果我点击按钮的顶部(红色箭头) - 覆盖 tableview 的位 - 按钮的 Action 不是被触发,而是按钮下方的单元格记录了点击。

我该如何防止这种情况发生?

最佳答案

如果 View 框架超出其父 View 框架,您将不会收到任何超出父 View 框架的触摸事件。这就是这里发生的情况,因为大按钮可能是 TabBar 的 subview 。将此添加按钮解析为 TabBarControllers View 的 subview 而不是 TabBar 并设置适当的约束。

另一种解决方案是为这个大按钮创建一个专用的 UIButton 子类并覆盖 hitTest(point:event:) 方法。

供引用: Capturing touches on a subview outside the frame of its superview using hitTest:withEvent:

关于swift - 当按钮覆盖在 tableview 顶部时,如何防止 tableview 单元格注册点击?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55675071/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com