How do we get the coordinates of an UIImageView pr

2019-02-22 04:40发布

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.

1条回答
叛逆
2楼-- · 2019-02-22 05:25

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
查看更多
登录 后发表回答