gpt4 book ai didi

ios - 应用自动布局后如何获取 UIImageView 大小?

转载 作者:可可西里 更新时间:2023-11-01 03:04:49 26 4
gpt4 key购买 nike

我的 Storyboard有 UIImageView,它会根据自动布局约束自动定位和缩放。

当应用程序运行时,此 UIImageView 会根据设备屏幕尺寸和自动布局约束适当调整大小和位置。

如何在屏幕上显示 后获取 UIImageView 框架?常见的 UIImageView.bounds 和 UIImageView.frame 值返回 Storyboard中使用的原始值,不反射(reflect)新的 UIImageView 大小。

最佳答案

为了在调整大小后获得 UIImageView 的正确框架/边界,您首先需要使用 [yourImageView layoutIfNeeded] 要求自动布局更新该布局。这将解决您的约束并更新您的 yourImage.bounds

[myImageView layoutIfNeeded];
NSLog(@"w: %f, h: %f", myImageView.bounds.size.width, myImageView.bounds.size.height);

关于ios - 应用自动布局后如何获取 UIImageView 大小?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28462809/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com