在触摸图像时,我想获取该像素的坐标,我尝试了一些代码,但没有获得用户触摸图像的确切位置。
这是我现有的代码
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
if let touch = touches.first {
let position = touch.location(in: self)
let Z1 = self.image!.size.height
let Z2 = self.image!.size.width
let Z3 = self.bounds.minY
let Z4 = self.bounds.minX
let Z5 = self.bounds.height
let Z6 = self.bounds.width
let pos1 = (position.x - Z4) * Z2 / Z6
let pos2 = (position.y - Z3) * Z1 / Z5
let point = CGPoint(x: pos1, y: pos2)
}
}