2017-08-06 53 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

没问题的伙计:) –