0

在我的 iOS 应用程序中,我将几个 UIImages 放在一个背面 UIImage 上,然后通过以编程方式截取屏幕截图来保存整个背面图像,并在其上添加所有子图像。

现在我想更改该保存图像的子视图 UIImages 位置。所以想知道如何检测子视图图像的位置,因为我已经将整个图像作为屏幕截图。

4

1 回答 1

0

Record their frame as converted to window coordinates. The pixels of the image should be the same as the frame origin (for normal) or double for retina. The screenshot is of the whole screen, so its dimensions are equivalent to the window frame. UIView has some convenience methods to convert arbitrary view frames to other view (or window) coordinates.

EDIT: to deal with content fit, you have to do the math yourself. You know the frame of the imageView, and you can ask the image for its size. Knowing the aspect ratio of each will let you determine in which dimension the image completely fits, and then you can compute the other dimension (which will be a value less than the imageView frame. Divide the difference of the view dimension minus the image dimension by two, and that lets you know the offset to the image inside the view. Now you can save the frame of the image as its displayed in the view.

于 2012-09-13T13:16:51.313 回答