任何人都可以建议我单击图像视图内的图像时,如何通过鼠标单击或触摸来获取图像的x和y坐标。

谢谢

最佳答案

首先,将点击手势侦听器添加到图像视图

let tapGestureRecognizer = UITapGestureRecognizer(target: self, action: #selector(imageTapped(tapGestureRecognizer:)))
imageView.isUserInteractionEnabled = true
imageView.addGestureRecognizer(tapGestureRecognizer)

然后在处理程序中,以这种方式在图像视图中找到水龙头的位置
func imageTapped(tapGestureRecognizer: UITapGestureRecognizer)
{
    let cgpoint = tapGestureRecognizer.location(in: imageView)

    print(cgpoint)
}

10-06 01:25