我正在制作一个小游戏,但我遇到了一个我无法解决的问题。问题是,当我触摸屏幕时,会出现一个动作。好吧,我希望如果有2个不同的触摸动作发生2次,不仅仅是在第一个。现在,如果同一设备上有2个玩家,那么首先接触的是获胜者,因为第二个玩家甚至无法调用该动作。如何调用动作两次处理作为输入的每次触摸?
换句话说,我想检测屏幕上有两个手指,并且在一个手指的正常动作中分割每个“手指”。
当然,我的行动发生在这里:
override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) {
//code to get input info
}
override func touchesEnded(touches: Set<UITouch>, withEvent event: UIEvent?) {
//calling actions with the arguments of touchesEnded and with the ones of touchesBegan
}
答案 0 :(得分:2)
在故事板中,您需要为视图启用“多次触摸”(它位于“属性”检查器的“交互”部分中。)您还可以通过编程方式设置此属性:
view.multipleTouchEnabled = true
但是,如果多次触摸同时发生,它们将在单个touchesBegan
事件中传递。要确保您的应用检测到两个触摸,请迭代touchesBegan
中的所有触摸:
override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) {
for touch in touches {
//code to get input info
}
}