[英]How do we get the coordinates of an UIImageView programmatically?
I would like to get the coordinates of an UIImageView programmatically. 我想以编程方式获取UIImageView的坐标。 How do I do this?
我该怎么做呢?
For example I have a square. 例如,我有一个正方形。 I want to get the coordinates of all the corners.
我想得到所有角落的坐标。 How must i proceed?
我该怎么办?
NSLog("%f", ImageView.frame.origin.x);
NSLog("%f", ImageView.frame.origin.y);
I get the topleft coordinate of the square. 我得到了广场的topleft坐标。
I must say that the square (imageview) rotates and that's why I must get it's coordinates. 我必须说方形(imageview)旋转,这就是为什么我必须得到它的坐标。
The coordinates in whose coordinate space? 坐标空间中的坐标?
Each UIView has its own coordinate space. 每个UIView都有自己的坐标空间。 You can refer to a view's size in its own coordinate space by asking for its
bounds
. 您可以通过询问其
bounds
在其自己的坐标空间中引用视图的大小。
A view's size and position in its parent view is called its frame
. 视图在其父视图中的大小和位置称为其
frame
。 In your example, you're asking for the image view's top left corner in its parent view's coordinate space. 在您的示例中,您要求在父视图的坐标空间中显示图像视图的左上角。
If that's what you want to do, then try these: 如果这是你想要做的,那么试试这些:
frame.origin.x
frame.origin.y
frame.size.width
frame.size.height
By adding those together you can get any coordinate: for example, the x coordinate of the top right would be 通过将它们添加到一起,您可以获得任何坐标:例如,右上角的x坐标将是
frame.origin.x + frame.size.width
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.