我压倒一切:
override func touchesBegan(touches: NSSet, withEvent event: UIEvent)
在斯威夫特。
我想知道,获得一个接触点是否正确:
var touchPoint: CGPoint! = event.touchesForView(self)?.anyObject()?.locationInView(self)
提前致谢!
答案 0 :(得分:2)
从iOS 8.3开始,touchesBegan
采用touches
参数,即Set<NSObject>
。它现在是Set<UITouch>
。所以,你会:
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
guard let point = touches.first?.location(in: view) else { return }
// use `point` here
}
在以前的iOS版本中,touchesBegan
被定义为NSSet
参数,如问题中所述,因此您可以:
override func touchesBegan(touches: NSSet, withEvent event: UIEvent) {
if let touch = touches.anyObject() as? UITouch {
let touchPoint = touch.locationInView(view)
...
}
}