我们如何获得的UIImageView坐标编程方式? [英] How do we get the coordinates of an UIImageView programmatically?
问题描述
我想获得的UIImageView坐标编程。我该怎么做呢?
I would like to get the coordinates of an UIImageView programmatically. 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.
我必须说,广场(ImageView的)转动,这就是为什么我一定要得到它的坐标。
I must say that the square (imageview) rotates and that's why I must get it's coordinates.
推荐答案
在其坐标坐标空间?
每个UIView的具有其自己的坐标空间。您可以通过请求其边界
。
Each UIView has its own coordinate space. You can refer to a view's size in its own coordinate space by asking for its bounds
.
一个视图在其父视图的大小和位置被称为其架
。在你的榜样,你要求其父图像视图的左上角视图的坐标空间。
A view's size and position in its parent view is called its 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
通过添加这些一起,你可以得到任何坐标:例如,在X的右上方协调会
By adding those together you can get any coordinate: for example, the x coordinate of the top right would be
frame.origin.x + frame.size.width
这篇关于我们如何获得的UIImageView坐标编程方式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!