逆转触摸事件在我的功能混淆了斯威夫特
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?){
for touch in touches{
let touchLocation = touch.location(in: self.view)
print("X: \(touchLocation.x) Y: \(touchLocation.y)")
}
}
我得到扭转Y值。如果我点击顶部,我会得到〜0值,如果我点击底部,我会得到很高的价值。这使得我的精灵im正在向错误的Y方向移动。
但是,如果我删除self.view中的'.view',它的工作原理应该如此。有没有人知道为什么它在我使用self.view时被逆转?
什么是自我类型? – dan
@dan这是一个SKView ... – Whirlwind
这是因为UIKit和SpriteKit的坐标系统有所不同。 UIKit在左上角有0,0。所以,正如OP已经指出的那样,仅仅使用self(这是一个场景)将按预期工作。 – Whirlwind