6

(iOS 7.0.3, Xcode 5.0.1)

I have a second UIWindow in my app used to display a custom magnifier above the status bar. However, once I set the rootViewController of this window (for interface rotation & some other stuff), the main window goes black during the interface rotation animation.

To reproduce: create single view iOS application and add the following to the main UIViewController.

// To @interface:
@property (nonatomic, strong) UIWindow *secondWindow;
// In viewDidLoad:
self.secondWindow = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
self.secondWindow.rootViewController = [[UIViewController alloc] initWithNibName:nil bundle:nil];
self.secondWindow.hidden = NO;

Any help appreciated.

Patrick Pijnappel
  • 7,317
  • 3
  • 39
  • 39

4 Answers4

6

I will add another answer, because I have found a workaround that actually works. Set the window's background color, as well as the view controller's view's background color to a color with an alpha of 0. Do not use clearColor, but rather use something like greenColor] colorWithAlphaComponent:0.0]; It works.

Léo Natan
  • 56,823
  • 9
  • 150
  • 195
  • @Andy Not in my experience. If the view controller's view has a `clearColor` background view, on rotation the background turns black. – Léo Natan Feb 23 '15 at 18:43
  • 2
    I have rootViewController.view.backgroundColor not even set to anything (nil) and UIWindow.backgroundColor = clearColor. All good. – pronebird Feb 23 '15 at 19:06
  • Setting `window.backgroundColor` as clear color works for me. – devxoul Jan 04 '16 at 12:25
  • Clear color worked for me when creating the viewcontroller for the window programmatically, but not by instantiating it from a Storyboard. – alasker Nov 15 '18 at 14:43
1

According to an Apple engineer on the dev forums, this is expected due to the window adding a black background to avoid things behind it to be seen (i.e. behind the main window normally). I opened and issue with the Apple bug tracker, #15398141.

Nevertheless, I worked around the issue by hiding the window in willRotateToInterfaceOrientation:duration: and unhiding it in didRotateFromInterfaceOrientation:, which luckily is not a big deal in this case.

Patrick Pijnappel
  • 7,317
  • 3
  • 39
  • 39
1

This is a known issue, and there are many radars open for it. Best solution so far for me is to add a view as a subview to the window, and manage rotation yourself. This works well.

Léo Natan
  • 56,823
  • 9
  • 150
  • 195
  • 1
    Yeah that's also a good approach. Note that you will also not be able to use iOS 7's UIViewController based status bar appearance, as it will query the second UIWindow (even without rootViewController set). – Patrick Pijnappel Nov 06 '13 at 05:13
0

Make window.opaque = No whose default value is YES. In my case it solved the problem.

Sam92
  • 45
  • 4