10

我能够确定 UIImageView 上的触摸事件的坐标。然后我需要将这些坐标转换为正在显示的图像的坐标 - 这应该是不同的,因为我的图像比 UIImageView 大得多,并且我正在使用 AspectFit 缩放图像。

给定 UIImageView 的视图坐标,确定触摸事件的图像坐标的最佳方法是什么?

4

1 回答 1

16

像这样的东西应该让你去。

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);

假设UIImageView被称为imageViewUITouch称为touchUIImage被称为image

于 2013-06-19T20:04:50.740 回答