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.
I must say that the square (imageview) rotates and that's why I must get it's coordinates.
The coordinates in whose coordinate space?
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
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With