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 的坐标?
基础教程推荐
- navigator.geolocation.getCurrentPosition 在 Android 浏览器上 2022-01-01
- 通过重定向链接在 Google Play 中打开应用 2022-01-01
- 如何从 logcat 中删除旧数据? 2022-01-01
- AdMob 广告未在模拟器中显示 2022-01-01
- Android:getLastKnownLocation(LocationManager.NETWORK_PROVIDER 2022-01-01
- iPhone - 获取给定地点/时区的当前日期和时间并将其与同一地点的另一个日期/时间进行比较的正确方法 2022-01-01
- libGDX 从精灵或纹理中获取像素颜色 2022-01-01
- iOS4 创建后台定时器 2022-01-01
- Cocos2d iPhone 非矩形精灵触摸检测 2022-01-01
- NSString intValue 不能用于检索电话号码 2022-01-01
