如何从视图控制器中获取 UIView 的大小? [英] How do I get the size of a UIView from within the View Controller?

查看:26
本文介绍了如何从视图控制器中获取 UIView 的大小?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 UIViewController 的 viewDidLoad 方法内部:

Inside the viewDidLoad method of a UIViewController:

NSLog(@"frame: %f %f", self.view.frame.size.width, self.view.frame.size.height);

设备处于横向:

frame: 748.000000 1024.000000

设备处于纵向:

frame: 768.000000 1004.000000

推荐答案

viewDidLoad 中,frame 可能没有调整到影响其最终大小的所有东西,例如旋转、状态栏高度变化、其他视图等.通常最好只在此处创建和设置您的对象;您可以在 viewWillLayoutSubviews 中检查最终框架.

In viewDidLoad, the frame may not have adjusted to all of the things that affect its final size, such as rotation, status bar height changes, other views, etc. It's generally best to only create and set up your objects here; you can inspect the finalized frame in viewWillLayoutSubviews.

这篇关于如何从视图控制器中获取 UIView 的大小?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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