简体   繁体   English

UIView大小和UIWindow rootViewController

[英]UIView size and UIWindow rootViewController

In following the exercises of a popular book for iOS Development I came across a line of code I don't understand and can't find an explanation for, so I thought I'd post on this community for insight... 在一本流行的iOS开发书的练习中,我遇到了一些我不理解但无法找到解释的代码,所以我想我会在这个社区发帖以获得洞察力......

In a UIViewController the view is initialized like this: 在UIViewController中,视图初始化如下:

-(void)loadView {
    [self setView:[[SomeView alloc] initWithFrame:CGRectZero]];
}

On the application delegate the controller is set as the rootViewController like this: 在应用程序委托上,控制器被设置为rootViewController,如下所示:

SomeController *sc = [[TouchViewController alloc] init];
[[self window] setRootViewController:sc];

How is it that the view is set to a zero rect and yet it comes up fullscreen when the application runs? 如何将视图设置为零rect,但是当应用程序运行时它会全屏显示?

My guess is that the rootViewController's view is set to the window's bounds by the window... but I have not been able to confirm this anywhere... 我的猜测是rootViewController的视图设置为窗口的窗口界限......但是我无法在任何地方确认这个...

Anyone? 任何人?

From the “View Management” section of the UIViewController Class Reference : UIViewController类参考的“视图管理”部分:

If a view controller is owned by a window object, it acts as the window's root view controller. 如果视图控制器由窗口对象拥有,则它将充当窗口的根视图控制器。 The view controller's root view is added as a subview of the window and resized to fill the window. 视图控制器的根视图将添加为窗口的子视图,并调整大小以填充窗口。

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

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