简体   繁体   中英

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM