Search code examples
model-view-controllerflip

Modal View Controller


I am using the following code in Xcode to horizontally flip between 2 views in an iPhone app

 -(IBAction)switchView:(id)sender{
    Algorithm2ViewController *Algorithm2ViewControllergo = [[Algorithm2ViewController    alloc]
                                                            initWithNibName:@"Algorithm2ViewController"                                                    bundle:nil];

    [UIView beginAnimations:@"flipview" context:nil];
    [UIView setAnimationDuration:1];
    [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
    [UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft 
                           forView:self.view cache:NO];
    [self.view addSubview:Algorithm2ViewControllergo.view];

    [UIView commitAnimations];
}

after the first flip I get an image of the coming view in the background before the completion of the flip how do I get rid of it?


Solution

  • I have figured this out in the second view add the following code

    -(IBAction)switchView2:(id)sender{
    
        SecondViewController *SecondViewControllergo = [[SecondViewController alloc]
                                                        initWithNibName:@"SecondView"
                                                        bundle:nil];
    
        [UIView beginAnimations:@"flipview" context:nil];
        [UIView setAnimationDuration:2];
        [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
        [UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft 
                               forView:self.view.superview cache:NO];
        [self.view addSubview:SecondViewControllergo.view];
        [self.view removeFromSuperview];
        [UIView commitAnimations]; 
        [SecondViewControllergo release];
    
    
    }
    

    The remove from superview line will remove the background image