Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do we get the coordinates of an UIImageView programmatically?

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.

like image 380
awlcs Avatar asked Aug 12 '10 13:08

awlcs


1 Answers

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
like image 94
Amy Worrall Avatar answered Sep 21 '22 14:09

Amy Worrall