标签:
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