[关闭]
@SanMao 2015-08-06T00:34:11.000000Z 字数 1952 阅读 1731

UIWindow

UI


UIWindow的显示

  1. self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
  2. self.window.backgroundColor = [UIColor redColor];
  1. UIViewController *rootVc = [[UIViewController alloc] init];
  1. self.window.rootViewController = rootVc;
  1. [self.window makeKeyAndVisible];

窗口的层级

  1. self.window.windowLevel = 1000;

通过storyboard手动加载控制器

  1. /**
  2. * 应用程序加载完成的时候调用
  3. */
  4. - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
  5. // 创建窗口
  6. self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
  7. // 从storyboard加载控制器
  8. UIStoryboard *sto = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
  9. // 创建控制器
  10. UIViewController *rootVc = [sto instantiateInitialViewController];
  11. UIViewController *contr = [sto instantiateViewControllerWithIdentifier:@"VC"];
  12. self.window.rootViewController = contr;
  13. // 显示窗口
  14. [self.window makeKeyAndVisible];
  15. return YES;
  16. }

通过Xib创建控制器

  1. // 创建窗口
  2. self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
  3. // 通过Xib创建控制器
  4. UIViewController *rootVc = [[UIViewController alloc] initWithNibName:@"VC" bundle:nil];
  5. self.window.rootViewController = rootVc;
  6. // 显示窗口
  7. [self.window makeKeyAndVisible];

控制器的View

  1. // 在这个方法中打印View的真实尺寸
  2. - (void)viewDidAppear:(BOOL)animated
  3. {
  4. [super viewDidAppear:animated];
  5. NSLog(@"%@",NSStringFromCGRect(self.view.frame));
  6. }
添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注