【发布时间】:2017-02-28 02:22:45
【问题描述】:
我正在尝试检测用户是在 SKScene 中触摸屏幕的左侧还是右侧。
我将以下代码放在一起,但无论触摸到哪里,它都只会输出“Left”。
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
for touch in touches {
let location = touch.location(in: self)
if(location.x < self.frame.size.width/2){
print("Left")
}
else if(location.x > self.frame.size.width/2){
print("Right")
}
}
}
【问题讨论】: