为什么iOS中的轻敲手势识别器的界面构建器操作不会触发? [重复]

问题描述 投票:-1回答:1

这个问题在这里已有答案:

在Xcode中的iOS中,我将轻敲手势识别器控件放到标签上,并控制拖动轻击手势识别器以创建界面构建器操作。当我点击标签时,界面构建器操作不会触发。这是我的代码:

@IBAction func actionTapLabelInstrumentDropDown(_ sender: UITapGestureRecognizer) {

    print("actionTapLabelInstrumentDropDown")

    instrumentDropDown.show()

}

print语句永远不会打印。

ios swift xcode interface-builder uitapgesturerecognizer
1个回答
2
投票

在问题的评论中根据@rmaddy观察写一个答案,这样社区就会更加明显。

默认情况下,标签不响应用户交互。您需要在标签上启用用户交互。


Adding my two cents:

如果你的UILabel在Storyboard / NIB中,你只需要检查右侧菜单中的User Interaction Enabled复选框。

如果您以编程方式创建UILabel,则需要调用以下函数才能启用它:

self.myLabel.userInteractionEnabled = true
© www.soinside.com 2019 - 2024. All rights reserved.