ios - 在多个类中添加 touchesBegan

标签 ios xcode swift

是否可以在项目中的多个位置或对象中使用 touchesBegan 方法?

例如,如果我有一个带有两个按钮的主类:

class GameScene: SKScene, SKPhysicsContactDelegate {
 let moveButton = MoveButton()
 let fireButton = FireButton()
 //add buttons to scene etc...
}

class MoveButton: SKSpriteNode {
 override func touchesBegan(touches: NSSet, withEvent event: UIEvent) {
  NSLog("moved!")
 }
}

class FireButton: SKSpriteNode {
 override func touchesBegan(touches: NSSet, withEvent event: UIEvent) {
  NSLog("fired!")
 }
}

目前我有类似的东西,但没有触发 touchesBegan,这是不正确的做法吗?

最佳答案

是的,在多个地方实现 touchesBegan 应该是完全没问题的。关于为什么不叫他们,也许这会有所帮助? Custom SKSpriteNode not detected during touch

关于ios - 在多个类中添加 touchesBegan,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27218627/

相关文章:

ios - 您无权将文件 “988BF072-A4B9-4ABE-9FB8-2F3A8EBC2E2C” 保存在文件夹 “CoreSimulator” 中

xcode - 将 XCode 编译错误与部署目标 iOS 5.1 相匹配

ios - 重写后总是调用 super?

ios - 如何从嵌套的 subview Controller 中检查屏幕的当前尺寸等级?

javascript - 如何在 ios 上将按钮操作捕获到 javascript 中?

iphone - 线程1:信号SIGABRT xcode 4.4 ios 5.1 Objective-c帮助>。<

ios - 如何使用动态单元格设置 View (UITableview)的背景?

ios - 如何在进入后台后5分钟内锁定应用程序

ios - iOS:UIImage发送到已释放实例

swift - 我无法启动 Main.storyboard 或 LaunchScreen.storyboard