用户触摸时获取屏幕坐标

时间:2021-06-02 21:21:47

I want to get the coordinates of screen when user touched it. I try touchesBegan Method but when i am using NSSet as a parameter i get an error. Can anyone guide me where am i mistaken how to solve this.

我想在用户触摸屏幕时获取屏幕坐标。我尝试touchesBegan方法,但当我使用NSSet作为参数时,我得到一个错误。任何人都可以指导我在哪里弄错了如何解决这个问题。

Thanks in advance...

提前致谢...

override func touchesBegan(touches: NSSet, withEvent event: UIEvent) {
    let touch = touches.anyObject()! as! UITouch
    lastPoint = touch.locationInView(self)
}

Error: Overriding method with selector 'touchesBegan:withEvent:' has incompatible type '(NSSet, UIEvent)'

错误:使用选择器'touchesBegan:withEvent:'的覆盖方法具有不兼容的类型'(NSSet,UIEvent)'

1 个解决方案

#1


0  

Try using:

尝试使用:

let touch = touches.first() as? UITouch

#1


0  

Try using:

尝试使用:

let touch = touches.first() as? UITouch