gpt4 book ai didi

ios - GestureRecognizer 不响应点击

转载 作者:IT王子 更新时间:2023-10-29 04:59:26 30 4
gpt4 key购买 nike

通过 UIImageView 的子类初始化后,我有以下代码行:

self.userInteractionEnabled = true
self.addGestureRecognizer(UITapGestureRecognizer(target: self, action: "handleTap:"))

我创建了必要的关联函数:

func handleTap(gestureRecognizer: UITapGestureRecognizer) {
print("In handler")
}

点击相关 View 时,“In handler was never printed to the console”。然后我删除了处理函数,看看编译器是否会提示缺少函数。它没有。

我真的被难住了。我真的很感激人们能对此有所启发。

更新:我的类实际上是一个 UIImageView 而不是 UIView

最佳答案

我使用的是 UITapGestureRecognizer,我使用 Storyboard 将其放置在 UILabel 上。

为了让它工作,我还必须在 Storyboard 的 UILabel Attributes Inspector 中标记为“User Interaction Enabled”的 block 中放置一个复选标记。

enter image description here

关于ios - GestureRecognizer 不响应点击,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26028455/

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