【发布时间】:2014-11-07 23:26:54
【问题描述】:
我需要以编程方式加载情节提要,在 iOS7 中,以下代码有效:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; // need to comment out in iOS8
self.window.backgroundColor = [UIColor cyanColor];
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
self.window.rootViewController = [storyboard instantiateInitialViewController];
[self.window makeKeyAndVisible];
return YES;
}
但在 iOS8 (XCode 6.1) 中,上述代码无法正确自动旋转:
和
我需要注释掉self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; 以更正自动旋转。
你知道第一行有什么不同吗?
【问题讨论】:
-
为什么要创建 UIWindow 对象?该属性已在应用委托中合成。
-
好的,那么“不能正确自动旋转”是什么意思?请记住,旋转和屏幕大小在 iOS8 中的处理方式不同。屏幕尺寸在 iOS8 中取决于方向。
标签: ios rotation ios8 uiwindow