码迷,mamicode.com
首页 > 移动开发 > 详细

计算视图相对坐标时convertPoint:toView: ,UIApplication sharedApplication - keyWindow is nil?

时间:2016-04-21 06:58:35      阅读:187      评论:0      收藏:0      [点我收藏+]

标签:

   UIWindow *window = [UIApplication sharedApplication].keyWindow;

 

 window 为nil的原因:在指定rootViewController之前,没有让window 先可视化

 

1.示例

 为nil:

 self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];

   self.window.backgroundColor = [UIColor whiteColor];

    self.window.rootViewController = [[ViewController alloc] init];

 

   [self.window makeKeyAndVisible]; 

 

 不为nil:

   self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];

 

   [self.window makeKeyAndVisible];

 

   self.window.backgroundColor = [UIColor whiteColor];

   self.window.rootViewController = [[ViewController alloc] init];

 

2.为nil的解决方法二

 用 delegate方法即可

 UIWindow *window = [[UIApplication sharedApplication].delegate window];

 

计算视图相对坐标时convertPoint:toView: ,UIApplication sharedApplication - keyWindow is nil?

标签:

原文地址:http://www.cnblogs.com/MrXHong/p/5415295.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!