2017-08-06 52 views
1

我正在製作iOS遊戲,並且需要知道如何獲取uitapgesturerecognizer的水龍頭位置。我做不是想要使用touchesBegan,touchesEnded等。我還需要知道如何檢查用戶是否雙擊了sprite節點。我已經設置了uitapgesturerecognizer的所有我需要知道的是如何找到觸摸的位置,並查看它是否與精靈節點位置相同。UITapGestureRecognizer - 檢測水龍頭位置是否有精靈(swift)

任何幫助,非常感謝!

+0

let target = gesture.view!,let translation = gesture.translation(in:self.view)。現在只需取translation.x和translation.y來獲取位置。 – matiastofteby

回答

0

假設你的精靈是一個繼承自UIView的類(我認爲它們通常是),那麼手勢識別器的處理函數應該看起來像這樣。

func handleDoubleTap(gestureRecognizer: UITapGestureRecognizer) { 

    let tapLocation = gestureRecognizer.location(in: gestureRecognizer.view) 
    if mySprite.frame.contains(tapLocation){ 
     print("tapped") 
    } 

} 
+0

感謝您的幫助! –

+0

沒問題的夥計:) –