如何在viewDidLayoutSubviews中获取正确的视图高度? [英] How do I get the correct view height in viewDidLayoutSubviews?

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

问题描述

- (void)viewDidLayoutSubviews {
    [super viewDidLayoutSubviews];
    NSLog(@"viewDidLayoutSubviews view.height: %f", self.view.frame.size.height);
}

在上面, view.height 总是 1024,无论设备的方向如何。即使旋转设备也会导致 viewDidLayoutSubviews 被调用,仍然输出1024.

In the above, view.height is always 1024 regardless of what orientation the device is in. Even rotating the device will cause viewDidLayoutSubviews to be called, and it will still output 1024.

但是视图呈现正常。

推荐答案

当iOS执行自动轮播时,它不会更改框架根视图控制器视图的属性。它所做的是应用变换和动画变换变换。要查看视图的实际大小,请检查 bounds 属性,而不是框架属性。

When iOS performs an automatic rotation, it does not change the frame property of the root view controller's view. What it does is apply a transform and animate the transform change. To see the "actual" size of your view, check the bounds property instead of the frame property.

引用 Apple的文档 c>转换属性:


警告:如果此属性不是标识转换,frame属性的值是未定义的,因此应该忽略。

Warning: If this property is not the identity transform, the value of the frame property is undefined and therefore should be ignored.

这篇关于如何在viewDidLayoutSubviews中获取正确的视图高度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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