Getting the coordinates from the location I touch the touchscreen

后端 未结 6 1276
温柔的废话
温柔的废话 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:16

    Taking this forward for Swift 3 - I'm using:

    override func touchesBegan(_ touches: Set, with event: UIEvent?) {
        if let touch = touches.first {
            let position = touch.location(in: self)
            print(position.x)
            print(position.y)
        }
    }
    

    Happy to hear any clearer or more elegant ways to produce the same result

提交回复
热议问题