IPhone - flipping views shows a white background

I am using flip animation to animate between two views in my view controller. The problem is that the background shows a white blank background during the animation. I would like to show a black background.

I tried to set the background color of the main view to black in both IB and code. But the background is still white.

Can anybody help me.

Thanks.

Adding Code

[self setContentView:[[UIView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]]]; contentView.backgroundColor = [UIColor blackColor]; [contentView addSubview:toolbar]; [self setView:contentView]; [contentView release]; frontView = [[FrontView alloc] initWithFrame:viewFrame]; [frontView setViewController:self]; [self.view insertSubview:frontView belowSubview:toolbar]; //Initializing the back view here too //on button click, executing normal flip code 

Even after that I get a white background

+6
iphone
source share
2 answers

I think your problem may be that UIWindow is displayed during the animation. To fix this problem, set the background color in the main window. You can do this in code or in IB.

+8
source share

You start by creating a fake main view and set its background to black:

 // Create the main view UIView *contentView = [[UIView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]]; contentView.backgroundColor = [UIColor blackColor]; self.view = contentView; [contentView release]; 

Then you create your front and back views and add them to your main view:

 // create front and back views UIView *frontView = ... UIView *backView = ... 

If you are using IB, skip the previous step and add your views directly

 // add the views [self.view addSubview:backView]; [self.view addSubview:frontView]; 

Now do the flip animation as usual.

EDIT: Maybe this won't work, because in the code you add a frontView under the toolbar. Add a backView first, then a frontView, and finally a toolbar using the addSubview: method. Then use the following code to animate the flip:

 - (IBAction) flipView{ // Start Animation Block CGContextRef context = UIGraphicsGetCurrentContext(); [UIView beginAnimations:nil context:context]; [UIView setAnimationTransition: UIViewAnimationTransitionFlipFromLeft forView:self.view cache:YES]; [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut]; [UIView setAnimationDuration:1.0]; // Animations [self.view exchangeSubviewAtIndex:0 withSubviewAtIndex:1]; // Commit Animation Block [UIView commitAnimations]; } 

Since the code does [self.view exchangeSubviewAtIndex: 0 withSubviewAtIndex: 1]; the order in which you add subviews matters.

0
source share

All Articles