当您将 viewcurrent
s view
s view
改为 ruotVictor
的 application
s window
/strong>时, 似乎被重新缩放为 。 否则您必须手工设置框架 。
我试过这个代码:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.window.backgroundColor = [UIColor whiteColor];
FooViewController *viewController = [[FooViewController alloc] init];
self.window.rootViewController = viewController;
[self.window makeKeyAndVisible];
FooViewController *viewController2 = [[FooViewController alloc] init];
[viewController.view addSubview: [viewController2 view]];
return YES;
}
view主计长
已调整大小, view主计长2
未调整大小。
另外:对于view主计长
,所有这些方法都称为:
viewDidLoad
viewWillLayoutSubviews
viewDidLayoutSubviews
viewDidAppear
仅 view Load
和 view didAppear
被调用。
有趣的是:在调用 view主计长
前,对 viewWillLayoutSubviews
进行了调整。
编辑:
我想这值得进一步测试 用以下代码:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.window.backgroundColor = [UIColor whiteColor];
FooViewController *viewController = [[FooViewController alloc] init];
NSLog(@"after init: self.view is %@", viewController.view);
self.window.rootViewController = viewController;
NSLog(@"after setting to rootViewController: self.view is %@", viewController.view);
[self.window makeKeyAndVisible];
NSLog(@"after makeKeyAndVisible: self.view is %@", viewController.view);
return YES;
}
结果如下:
viewDidLoad: frame = (0 0; 0 0)
after init: frame = (0 0; 0 0)
after setting to rootViewController: frame = (0 0; 0 0)
after makeKeyAndVisible: frame = (0 20; 320 460)
viewWillLayoutSubviews: frame = (0 20; 320 460)
viewDidLayoutSubviews: frame = (0 20; 320 460)
viewDidAppear: frame = (0 20; 320 460)
因此,“强势”代码[自. 窗口使Key和可视];“/code/强”是罪魁祸首。