设备旋转时更改UIWindow背景颜色

jls*_*ker 3 iphone uiwindow ipad uiviewanimation ios

UIWindow最初有白色背景.我想在设备旋转时将背景更改为蓝色(永久).但实际发生的是颜色短暂闪烁蓝色然后又回到白色.

在app委托中:

- (void)application:(UIApplication *)application didChangeStatusBarOrientation:(UIInterfaceOrientation)oldStatusBarOrientation
{
    self.window.backgroundColor = [UIColor blueColor];
}
Run Code Online (Sandbox Code Playgroud)

这个代码按预期调用,但是当旋转完成时,-[UIWindow setBackgroundColor:]第二次调用(正如我通过子类化发现的那样UIWindow).第二个调用的调用堆栈是:

-[UIWindow setBackgroundColor]
-[UIWindow _finishedFullRotation:finished:context:]
-[UIViewAnimationState sendDelegateAnimationDidStop:finished:]
-[UIViewAnimationState animationDidStop:finished:]
-run_animation_callbacks
...
Run Code Online (Sandbox Code Playgroud)

编辑(@ VinceBurn的答案)

该应用程序只有一个视图(来自Xcode的基于视图的应用程序项目模板).我现在已将视图的背景颜色(在IB中)设置为0%不透明度.仍然得到相同的结果.

为了确保白色不是来自其他一些默认颜色设置,我现在最初将窗口的背景颜色设置为绿色:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {    

    // Override point for customization after application launch.

    // Add the view controller's view to the window and display.
    self.window.backgroundColor = [UIColor greenColor];
    [self.window addSubview:viewController.view];
    [self.window makeKeyAndVisible];

    return YES;
}
Run Code Online (Sandbox Code Playgroud)

旋转时,它会短暂闪烁蓝色但返回绿色.

jls*_*ker 5

我最终做的是改变活动UIViewController视图的背景颜色,而不是UIWindow:

- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation
{
    self.view.backgroundColor = [UIColor blueColor];
}
Run Code Online (Sandbox Code Playgroud)

我一直试图设置背景颜色的原因UIWindow是为了在整个应用程序中获得相同的背景颜色.显然,实现这一目标的最简单方法是让UIViewController应用程序中的所有内容都继承自UIViewController实现的子类-didRotateFromInterfaceOrientation:.