单击UIImageView时如何获取触摸位置?

时间:2018-05-03 20:32:08

标签: ios swift uiimageview

我希望能够确定用户在Swift中单击UIImageView的x,y位置。

1 个答案:

答案 0 :(得分:0)

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