简体   繁体   English

UIView更改大小

[英]UIView changing size

I have a view that I'm creating in the loadview like this: 我有一个像这样在loadview中创建的视图:

- (void)loadView {
UIView *mainView = [[UIView alloc] initWithFrame:[UIApplication sharedApplication].keyWindow.bounds];
self.view = mainView;
[mainView release];

} }

So, if I print the view I got the result: > OK, that's what I wanted, 767x1024 因此,如果我打印视图,则会得到结果:> OK,这就是我想要的767x1024

The problem is, if I call this method: 问题是,如果我调用此方法:

[[UIApplication sharedApplication] setStatusBarHidden:NO withAnimation:UIStatusBarAnimationSlide];

and present a modalViewController and then dismiss it, on my previous view controller, printing the method viewDidAppear and viewWillAppear I got this: 并呈现一个modalViewController,然后在我以前的视图控制器上将其关闭,打印方法viewDidAppear和viewWillAppear我得到了:

viewWillAppear: viewWillAppear:

[<UIView: 0x4e946a0; frame = (0 0; 768 1024); layer = <CALayer: 0x4e946d0>>]

viewDidAppear: viewDidAppear:

[<UIView: 0x4e946a0; frame = (0 0; 768 1004); layer = <CALayer: 0x4e946d0>>]

Why the view size is changing by 20? 为什么视图大小变化20? I know that has something to do with the status bar, but can't figure it out. 我知道这与状态栏有关,但无法弄清楚。

Thanks. 谢谢。

You are right. 你是对的。 Status bar default size is 20 pixel in height. 状态栏的默认大小为20像素高。 UIViewController automatically adjust child view size as status bar appears. 随着状态栏的出现,UIViewController自动调整子视图的大小。 According to apple documentation "When a view controller is displayed on screen, its root view is typically resized to fit the available space, which can vary depending on the window's current orientation and the presence of other interface elements such as the status bar." 根据Apple的文档,“当视图控制器显示在屏幕上时,通常会调整其根视图的大小以适合可用空间,视窗口的当前方向和其他界面元素(例如状态栏)的存在而定,该可用空间可能会有所不同。” http://developer.apple.com/library/ios/#documentation/uikit/reference/UIViewController_Class/Reference/Reference.html http://developer.apple.com/library/ios/#documentation/uikit/reference/UIViewController_Class/Reference/Reference.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM