Converting UIImageView Touch Coordinates to UIImage Coordinates

前端 未结 1 1897
攒了一身酷
攒了一身酷 2020-12-09 05:48

I\'m able to determine the coordinates of a touch event on a UIImageView. I need to then convert these coordinates to the coordinates of the image being displayed - which sh

相关标签:
1条回答
  • 2020-12-09 06:35

    Something like this should get you going.

    CGPoint imageViewPoint = [touch locationInView:imageView];
    
    float percentX = imageViewPoint.x / imageView.frame.size.width;
    float percentY = imageViewPoint.y / imageView.frame.size.height;
    
    CGPoint imagePoint = CGPointMake(image.size.width * percentX, image.size.height * percentY);
    

    Assuming the UIImageView is called imageView the UITouch is called touch and the UIImage is called image.

    0 讨论(0)
提交回复
热议问题