应用自动布局后如何获取UIImageView大小? [英] How to get UIImageView size after autolayout is applied?

查看:45
本文介绍了应用自动布局后如何获取UIImageView大小?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的情节提要中具有UIImageView,它会根据自动布局约束自动定位和缩放.

My storyboard has UIImageView which is automatically positioned and scaled by autolayout constraints.

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

When application runs, this UIImageView is properly resized and positioned according to device screen size and autolayout constraints.

如何之后显示在屏幕上的UIImageView框架?常见的UIImageView.bounds和UIImageView.frame值返回原始值,这些值已在情节提要中使用,并且不反映新的UIImageView大小.

How I can get UIImageView frame after it is displayed on the screen? Common UIImageView.bounds and UIImageView.frame values return original values which were used in storyboard and does not reflect new UIImageView size.

推荐答案

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

In order to get the right frame/bounds of your UIImageView after resizing, you need first ask auto-layout to update that layout using [yourImageView layoutIfNeeded]. that will solve your constraints and update your yourImage.bounds.

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

这篇关于应用自动布局后如何获取UIImageView大小?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆