Getting the coordinates from the location I touch the touchscreen

后端 未结 6 1291
温柔的废话
温柔的废话 2020-12-03 05:15

I try to get the coordinates from the location where I hit the touchscreen to do put a specific UIImage at this point.

How can I do this?

6条回答
  •  情话喂你
    2020-12-03 05:28

    This is work in Swift 2.0

    override func touchesBegan(touches: Set, withEvent event: UIEvent?) {
        if let touch = touches.first {
            let position :CGPoint = touch.locationInView(view)
            print(position.x)
            print(position.y)
    
        }
    }
    

提交回复
热议问题