切换view的动画

代码:

#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
上一篇:【转】使用ngrok快速地将本地Web服务映射到外网


下一篇:大华等其他NVR接入海康IPC H.264方法