【发布时间】:2023-04-05 18:38:01
【问题描述】:
我正在尝试检测用户是否在 SKScene 中触摸屏幕的左侧或右侧。
我将以下代码放在一起,但无论触摸到哪里,它都只会输出“Right”。
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")
}
}
}
【问题讨论】:
-
不会右大于 (>) 左小于 (
-
没错..现在我触摸任何地方时它都会输出“Left”。