TouchesBegan没有开火

时间:2016-02-14 20:18:10

标签: ios iphone swift autolayout swift2

我的故事板看起来像这样:

Controller
    top/bottom layout guide
    view
        UIview
            UIButton
        UIImageView

我的触控功能:

override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) {
    print("touched")
}

当我触摸屏幕上的任何地方(按钮所在的位置除外)时,我的记录会被记录。

UIImageView占据整个屏幕,按钮只是中间50x50像素的正方形。虽然我可以看到的是当我点击按钮没有被触发的位置的顶部时的图像。单击其他任何地方正确触发事件

2 个答案:

答案 0 :(得分:1)

检查元素用户交互启用属性是否为true。希望有所帮助。 :)

答案 1 :(得分:1)

您必须确保通过@IBAction将UIButton设置为适当的方法。在main.storyboard屏幕中,您可以右键单击或按住Option键单击UIButton并将其拖动到相应的类。