15

I have some pretty standard flipping action going on:

[UIView beginAnimations:@"swapScreens" context:nil];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:self.view cache:YES];
[UIView setAnimationDuration:1.0];
[self.view exchangeSubviewAtIndex:0 withSubviewAtIndex:1];
[UIView commitAnimations]; 

To Apple's credit, this style of animation is amazingly easy to work with. Very cool, and I've been able to animate transitions, flips, fades etc. throughout the app very easily.

Question: During the flip transition, the background visible 'behind' the two views during the flip is white and I'd like it to be black. I've:

  • Set the background of the containing view (self.view above) - no dice. I really thought that would work.
  • Set the background of each view to black - no dice. I didn't think this would work although you give different things a shot to understand better :)
  • Google'd like crazy; keep landing on Safari-related listings.

Thanks in advance!

Rob S.
  • 426
  • 4
  • 16

2 Answers2

19

You could use a color or an image. You can add a view to do it:

UIWindow *window = [appDelegate window];
UIView *bgView = [[UIView alloc] init];
[bgView setBackgroundColor:[UIColor blackColor]];
[window addSubView:bgView];

Or set the background color on the window directly:

[[appDelegate window] setBackgroundColor:[UIColor blackColor]];
Nathan
  • 11,938
  • 12
  • 55
  • 62
Mike
  • 8,853
  • 3
  • 35
  • 44
  • 7
    I'm partially wrong. Digging in to xcode, there actually is a backgroundColor property on UIWindow. You can skip the UIView step. Just do [[appDelegate window] setBackgroundColor:[UIColor blackColor]]; – Mike May 24 '10 at 18:33
  • 12
    Or just do it in ApplicationDidFinishLanuching: with a simple window.backgroundColor = [UIColor blackColor]; – Brad The App Guy May 24 '10 at 19:06
  • 1
    i am still getting the white color. – ichanduu Jun 13 '12 at 11:09
  • It might be the navigation controllers view that needs the background colour changed if using one of those. – malhal Jan 03 '16 at 20:35
6

You can also set the background color on the Window in MainWindow.xib in IB if that's easier.

johna
  • 71
  • 1
  • 2