开发者

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.fra开发者_如何转开发me.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
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜