iPhone - flipping views shows a white background

前端 未结 2 1778
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-20 18:39

I am using the flip animation to animate between two views in my viewcontroller. The problem is that the background shows a white blank background while the animation is tak

相关标签:
2条回答
  • 2020-12-20 19:22

    I think your issue might be that the UIWindow is shown during the animation. To fix this issue, set the background color of your main window. You can do this in code or in IB.

    0 讨论(0)
  • 2020-12-20 19:38

    You begin 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 directly your views

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

    Now do the flip animation as usual.

    EDIT: Probably it does not work because in your code you are adding the frontView below the toolbar. Add first the backView, then the frontView and finally the 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 performs [self.view exchangeSubviewAtIndex:0 withSubviewAtIndex:1]; the order in which you add the subviews is relevant.

    0 讨论(0)
提交回复
热议问题