0

目前我做的事情看起来有点模糊,因为我正在处理我的 UI 对象的点,但我想要做的是获取 UI 对象(在我的情况下是 UIImageView)的宽度和高度(以像素为单位)。

这可能吗?我查看了文档,但没有看到任何看起来相关的内容。

有人可以帮忙吗?

谢谢!

4

1 回答 1

0

你试过这个吗?

[object frame].size.height

[object frame].size.width

我很确定任何具有视觉表示的东西都会有一个 frame 属性来指示它的位置。当然,origin对象框架的 是相对于其容器的,但size应该始终可用。

编辑/更新:

我误读了最初的问题,它也想转换点-> 像素。以下是确保您正确理解的方法:

float scale;
if ([[UIScreen mainScreen] respondsToSelector:@selector(scale)]) {
    // This message was implemented in iOS 4.0
    scale = [[UIScreen mainScreen] scale];
} else {
    // Anything that is running < 4.0 doesn't have a Retina display
    scale = 1.0;
}

然后,将高度和宽度值乘以比例以获得实际像素数。

于 2012-04-29T20:41:01.713 回答