[IOS界面切换实现动画

- (IBAction)switchViews:(id)sender { 
    [UIView beginAnimations:@"View Flip" context:nil]; 
    [UIView setAnimationDuration:1.25]; 
    [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
    if (self.secondViewController.view.superview == nil) {//表示当前视图是根视图 
        if (self.secondViewController == nil) { 
            self.secondViewController = [[SecondViewController alloc] initWithNibName:@"SecondView" bundle:nil];
        } 
        [UIView setAnimationTransition: UIViewAnimationTransitionFlipFromRight forView:self.view cache:YES]; 
        [self.firstViewController.view removeFromSuperview]; 
        [self.view insertSubview:self.secondViewController.view atIndex:0]; 
    } else { 
        if (self.firstViewController == nil) { 
            self.firstViewController = [[FirstViewController alloc] initWithNibName:@"FirstView" bundle:nil]; 
        } 
        [UIView setAnimationTransition: UIViewAnimationTransitionCurlUp forView:self.view cache:YES]; 
        [self.secondViewController.view removeFromSuperview]; 
        [self.view insertSubview:self.firstViewController.view atIndex:0]; 
    } 
    [UIView commitAnimations]; 
}

效果:

         

posted @ 2012-08-02 19:35  大脚印  阅读(1004)  评论(0编辑  收藏  举报