查看高度问题(续) [英] View height problems (continued)

查看:143
本文介绍了查看高度问题(续)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我在这里遇到的问题(仍未解决)的延续:链接

This is in continuation to the problem I had here(which is still unresolved): link

但这可能有助于了解问题是什么。
我创建了一个简单的测试项目('Empty Application'),并添加了一个带有XIB文件的视图控制器(复选框:'选择用户界面的XIB文件')。代码如下:

But this may help understand what is the problem. I created just a simple test project ('Empty Application') and added a view controller with a XIB file (check box: 'With XIB file for user interface' selected). Code looks like this:

- (void)viewDidLoad
{
    [super viewDidLoad];
    NSLog(@"didLoad: %@",NSStringFromCGRect(self.view.bounds));

    // Do any additional setup after loading the view from its nib.
}

-(void) viewDidAppear:(BOOL)animated
{
    NSLog(@"didAppear: %@",NSStringFromCGRect(self.view.bounds));

}

这是输出:

2013-07-26 17:05:28.502 testtest[5926:c07] didLoad: {{0, 0}, {320, 548}}
2013-07-26 17:05:28.506 testtest[5926:c07] didAppear: {{0, 0}, {320, 460}}

它们是如何不同的?

(ps。我在6.1模拟器上测试)

(ps. I am testing on 6.1 simulator)

推荐答案

当调用 viewDidLoad 方法时,您的视图控制器刚刚从您的故事板XIB,因此视图尺寸等于您在XIB中看到的尺寸(这些尺寸看起来像是iPhone 5的高度尺寸)。

When the viewDidLoad method is called, your view controller has only just been loaded from your storyboard or XIB, and so the view dimensions are equal to those that you have in the XIB (those looks like iPhone 5 height dimensions).

后来,当 viewDidAppear:被调用,视图已经出现在屏幕上,所以它被适当调整大小以适合屏幕上,所以它的尺寸可能会不同于你的故事板中的,因此不同

Later, when viewDidAppear: is called, the view has already appeared on the screen, so it has been resized appropriately to actually fit on the screen, so its dimensions may be different to those in your storyboard, and consequently different to those that are set when the view is loaded.

在你的情况下,它看起来像你的故事板或XIB文件设置为iPhone 5屏幕尺寸(548 = 1136 / 2 - 状态栏),并且您在iPhone 5之前的模拟器或具有480x320点屏幕的设备上进行测试,因此视图调整为高到460点,以适应屏幕。

In your case, it looks like your storyboard or XIB file is set to iPhone 5 screen size (548 = 1136/2 - status bar), and you are testing in a pre-iPhone 5 simulator or device with a 480x320 point screen, so the view gets resized down to 460 points high to fit on the screen.

这篇关于查看高度问题(续)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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