从我触摸屏的位置获取坐标

我尝试从点击触摸屏的位置获取坐标,以在此时放置特定的UIImage。

我怎样才能做到这一点?

回答:

UIResponder子类中,例如UIView

override func touchesBegan(touches: NSSet, withEvent event: UIEvent) {

let touch = touches.anyObject()! as UITouch

let location = touch.locationInView(self)

}

这将返回一个CGPoint视图坐标。

override func touchesBegan(touches: NSSet, withEvent event: UIEvent) {

let touch = touches.first!

let location = touch.location(in: self)

}

override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {

let touch = touches.first!

let location = touch.location(in: self.view)

}

以上是 从我触摸屏的位置获取坐标 的全部内容, 来源链接: utcz.com/qa/410973.html

回到顶部