touchesBegan()没有在子视图上调用

时间:2017-08-12 18:28:40

标签: ios swift sprite-kit

我有一个名为SKButton的类,SKSpriteNode的子类,它将touchesBegan()函数实现为print("hello")。但是当我在我的视图中添加SKButton对象时,touchesBegan()永远不会在按钮上调用。为什么呢?

2 个答案:

答案 0 :(得分:3)

您需要确保在视图的所有超级视图中启用了userInteractionEnabled。

答案 1 :(得分:1)

还要记住,在项目中从Swift 2.3到Swift 3可能会触发方法名称的警告,你使用默认修复更新它然后你最终会像我一样想知道为什么这些方法与触摸有关尽管您设置了userInteractionEnabled,但仍未调用。修复:确保根据您当前的Swift版本编写方法名称!