I have an image with size 480x360
and am displaying in UIImageview
with frame (0, 0, 320, 568)
with aspectfill
.
W
Finding the pixel location of the touch in Swift:
guard let image = imageView.image else {
return
}
let x = image.size.width / imageView.frame.size.width
let y = image.size.height / imageView..frame.size.height
// Assuming touchLocation is CGPoint received from Touch event
var touchLocation: CGPoint
let locationInImageView = CGPoint(x: touchLocation.x * x, y: touchLocation.y * y);