我是压倒一切的:
override func touchesBegan(touches: NSSet, withEvent event: UIEvent)
在斯威夫特。
我想知道,这是正确的得到一个触点:
var touchPoint: CGPoint! = event.touchesForView(self)?.anyObject()?.locationInView(self)
提前感谢!
发布于 2014-11-07 23:39:17
在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)
...
}
}
https://stackoverflow.com/questions/26811755
复制相似问题