tvos swift spritekit - UITapGestureRecognizer 没有响应

tvos swift spritekit - UITapGestureRecognizer not responding

我根本无法让这个手势响应。

    self.isUserInteractionEnabled = true
    let tap = UITapGestureRecognizer(target: self, action: #selector(self.movePlayer(_:)))
    tap.allowedPressTypes = [NSNumber(value: UIPressType.playPause.rawValue)]
    view?.addGestureRecognizer(tap)

和函数:

func movePlayer(_ sender: UITapGestureRecognizer){
    player.run(SKAction.moveBy(x: 200, y: 0, duration: 10))
    print("Right!")
}

按下模拟器遥控器上的播放按钮时什么也没有发生。我错过了什么?

点按手势识别器代码看起来不错。你添加到哪里,是在didMoveToView中吗?

我最近在玩新的 iOS10

override func sceneDidLoad() { }

方法,我注意到那里添加的手势识别器不起作用。

这在模拟器中有效

 class GameScene: SKScene, SKPhysicsContactDelegate {

      override func didMove(to view: SKView) {

          self.isUserInteractionEnabled = true
          let tap = UITapGestureRecognizer(target: self, action: #selector(self.movePlayer(_:)))
          tap.allowedPressTypes = [NSNumber(value: UIPressType.playPause.rawValue)]
          view.addGestureRecognizer(tap)
     }

     func movePlayer(_ sender: UITapGestureRecognizer){
         print("Right!")

     }
 }

希望对您有所帮助