2009-07-03 33 views
6

我正在使用翻转动画在我的视图控制器中的两个视图之间进行动画。问题是背景在动画发生时显示一个白色的空白背景。我想展示一个黑色的背景。iPhone - 翻转视图显示白色背景

我试图在IB和代码中设置主视图的背景颜色为黑色。但背景仍然是白色的。

有人可以帮助我。

谢谢。

添加代码

[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 

即使在此之后,我得到一个白色背景

回答

8

我认为你的问题可能是在动画期间显示UIWindow。要解决此问题,请设置主窗口的背景颜色。您可以在代码或IB中执行此操作。

0

首先创建一个假的主视图,并设置其背景为黑色:

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

然后,您创建正面和背面视图,并将它们添加到您的主视图中:

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

如果使用的是IB,跳过前面的步骤,直接添加你的意见

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

现在做翻转动画如常。

编辑:可能它不工作,因为在你的代码中,你正在工具栏下方添加frontView。首先使用addSubview:方法添加backView,然后添加frontView,最后添加工具栏。然后,使用下面的代码进行动画处理的翻转:由于代码执行

- (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]; 

} 

[self.view exchangeSubviewAtIndex:0 withSubviewAtIndex:1];您添加子视图的顺序是相关的。

+0

谢谢。我无法让它工作。在问题中发布代码 – lostInTransit 2009-07-03 14:04:45