我们如何以编程方式获取 UIImageView 的坐标?

How do we get the coordinates of an UIImageView programmatically?(我们如何以编程方式获取 UIImageView 的坐标?)
本文介绍了我们如何以编程方式获取 UIImageView 的坐标?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想以编程方式获取 UIImageView 的坐标.我该怎么做?

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.

推荐答案

坐标在谁的坐标空间?

每个 UIView 都有自己的坐标空间.您可以通过询问 bounds 来引用视图在其自己的坐标空间中的大小.

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.

视图在其父视图中的大小和位置称为其frame.在您的示例中,您要求图像视图在其父视图的坐标空间中的左上角.

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

通过将它们加在一起,您可以获得任何坐标:例如,右上角的 x 坐标将是

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

这篇关于我们如何以编程方式获取 UIImageView 的坐标?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Pushing UIViewController above UITabBar(将UIView控制器推送到UITabBar上方)
java.lang.IllegalStateException: SimpleTypeImpl should not be created for error type(异常:不应为错误类型创建SimpleTypeImpl)
Android IllegalArgumentException: The tag for fragment_XXX is invalid. Received: layout-sw600dp/fragment_XXX_0(Android IlLegalArgumentException:Fragment_XXX的标签无效。收到:Layout-sw600dp/Fragment_XXX_0)
iOS convert audio sample rate from 16 kHz to 8 kHz(IOS将音频采样率从16 kHz转换为8 kHz)
Enforcing an audio sampling rate in iOS(在iOS中强制音频采样率)
HTTPS request using volley(使用 volley 的 HTTPS 请求)