How do we get the coordinates of an UIImageView programmatically?(我们如何以编程方式获取 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 的坐标?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:我们如何以编程方式获取 UIImageView 的坐标?


基础教程推荐
- Android:对话框关闭而不调用关闭 2022-01-01
- UIWebView 委托方法 shouldStartLoadWithRequest:在 WKWebView 中等效? 2022-01-01
- 当从同一个组件调用时,两个 IBAction 触发的顺序是什么? 2022-01-01
- 如何让对象对 Cocos2D 中的触摸做出反应? 2022-01-01
- 如何在没有IB的情况下将2个按钮添加到右侧的UINavigationbar? 2022-01-01
- android 应用程序已发布,但在 google play 中找不到 2022-01-01
- 如何在 UIImageView 中异步加载图像? 2022-01-01
- 如何在 iPhone 上显示来自 API 的 HTML 文本? 2022-01-01
- Kivy Buildozer 无法构建 apk,命令失败:./distribute.sh -m “kivy"d 2022-01-01
- 在 gmail 中为 ios 应用程序检索朋友的朋友 2022-01-01