代码:
#import "MainViewController.h" @interface MainViewController () @end @implementation MainViewController - (void)viewDidLoad
{
[super viewDidLoad]; UIView *view1 = [[UIView alloc]initWithFrame:[[UIScreen mainScreen] bounds]];
view1.backgroundColor = [UIColor blueColor]; UIView *view2 = [[UIView alloc]initWithFrame:[[UIScreen mainScreen] bounds]];
view2.backgroundColor = [UIColor yellowColor]; [self.view addSubview:view1];
[self.view addSubview:view2];
} -(void) changeView
{
NSLog(@"change view");
CGContextRef context = UIGraphicsGetCurrentContext();
[UIView beginAnimations:nil context:context];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[UIView setAnimationDuration:1.0]; [UIView setAnimationTransition: UIViewAnimationTransitionFlipFromRight forView:self.view cache:YES];
[self.view exchangeSubviewAtIndex: withSubviewAtIndex:]; [UIView setAnimationDelegate:self];
[UIView setAnimationDidStopSelector:nil];
[UIView commitAnimations];
} -(void) changeView2
{
CATransition *animation = [CATransition animation];
[animation setDuration:1.25f];
[animation setTimingFunction:[CAMediaTimingFunction
functionWithName:kCAMediaTimingFunctionEaseIn]];
[animation setType:kCATransitionReveal];
[animation setSubtype: kCATransitionFromRight];
[self.view.layer addAnimation:animation forKey:@"Reveal"]; [self.view exchangeSubviewAtIndex: withSubviewAtIndex:]; [CATransaction commit];
} -(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
[self changeView];
}
@end