シングルタップとダブルタップの両方を実装しました。しかし、画面をダブルタップするたびに、シングルタップコードも実行されます。下記のコードをご覧ください:ダブルタップがtouchesで発生したときにシングルタップが呼び出されないようにする方法
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
let touch = touches.first as UITouch!
let touchLocation = touch?.location(in: self)
let touchedNode = self.atPoint(touchLocation!)
if touch?.tapCount == 1 {
print("single tap")
if let name = touchedNode.name {
if name == "enemySprite"
{
//handle single Tap
}
}
}
if touch?.tapCount == 2 {
print("double tap")
if let name = touchedNode.name {
if name == "enemySprite"
{
//handle double Tap
}
}
}
}
タップカウントを相互排他的にするにはどうすればよいですか? Apurvの答えと旋風さんのコメントに基づいて
UPDATE
私は、次のコードショーの仕事を考えました。それが機能しないと、私はエラーが
Value of type ’SKView?’ has no member ‘sampleTapGestureTapped(recognizerMethod:)’ and
Value of type ’SKView?’ has no member ‘sampleTapGestureTapped(recognizerMethod2:)’
は、タップジェスチャー変数の宣言も
を指して、言ってもらう
override func didMove(to view: SKView) {
var tapGesture = UITapGestureRecognizer(target: self, action: #selector(self.view.sampleTapGestureTapped(recognizerMethod:)))
self.view.addGestureRecognizer(tapGesture!)
tapGesture.numberOfTapsRequired = 1;
var tapGestureDouble = UITapGestureRecognizer(target: self, action: #selector(self.view.sampleTapGestureTapped(recognizerMethod2:)))
self.view.addGestureRecognizer(tapGestureDouble!)
tapGestureDouble.numberOfTapsRequired = 2;
[tapGesture requireGestureRecognizerToFail : tapGestureDouble];
}
、私はエラー
Expected expression in the container literal
を取得します
は、上記の方法の最後の行を指しています。
私はここに何か不足していると思いますが、これについていくつかの助けと説明をいただきたいと思います。
問題は、iOSのは、それを見て、あなただけのちょうどあなたと同じように:-)一度か二度画面をタッチしているシングルまたは画面をダブルタップしていないということです最初のタッチがあったのを見てスワイプを検出するためにtouchesBeganを使用していないタッチの動きおよび方向を監視する。 (私は、iOSの初期にはタップ、スワイプ、ピンチ、回転などのためにやらなければならないことはまさに悪夢だと思うが) –