swift : Button click stops tapGestureDidRecognize on the parent View

标签 swift tap

是否可以单击按钮并让点击向下滴到按钮的父 View ?我尝试禁用按钮并检测到点击,但是是否可以单击按钮,执行某些操作,然后让点击事件慢慢下降?

UIViewControllerWrapperView包含UIView包含UIView包含UIButton

当我点击/按下按钮时应该像这样,

点击按钮 > UIView 被点击 > UIView 被点击 > UIViewControllerWrapperView 检测点击

编辑: 我可以检测 UIViewControllerWrapperView 上的点击,但是,如果我单击按钮,则不会检测到点击,因为我假设点击事件由按钮处理,而按钮又会阻止下面的 View 检测到点击。

最佳答案

isUserInteractionEnabled 属性

尝试设置 UIButton 的 isUserInteractionEnabled属性设置为false。 UIButton 的默认值为 true

请注意,isUserInteractionEnabled 是在 UIButton 继承的 UIView 类上声明的。

 

在代码中设置isUserInteractionEnabled

button.isUserInteractionEnabled = false

 

在 Interface Builder 中设置 isUserInteractionEnabled

在 UIButton 的属性检查器中:

enter image description here

关于 swift : Button click stops tapGestureDidRecognize on the parent View,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41213678/

相关文章:

linux - 如何编写 stap (systemtap) 脚本来查看某个进程是否调用了特定的内核函数?

node.js - 测试 fastify 路由时如何修复 "not ok timeout!"?

swift - 如何在捕获中打印错误

ios - 如何将 String 转换为 JSON,以便我可以将其解析为对象

ios - 自动调整 UIWebView 的大小以适应内容

c# - 在 WPF 应用程序中在后台执行任务

perl - Test::BDD::Cucumber::Harness::Html 中断 UTF-8 字符

ios - 如何快速删除核心数据中的实体?

ios - Swift `=String()` 和 `: String!` 中的 2 个字符串初始化有什么区别

node.js - 处理磁带测试中的错误?