实现ios动画有两种方法:一种UIView层面的,一种是使用CATransition.
[objc] view plain copy 在CODE上查看代码片派生到我的代码片
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
UIView *redView = [[UIView alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
redView.backgroundColor = [UIColor redColor];
[self.view addSubview:redView];
UIView *yellowView = [[UIView alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
yellowView.backgroundColor = [UIColor yellowColor];
[self.view addSubview:yellowView];
UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[button setTitle:@"改变1" forState:UIControlStateNormal];
button.frame = CGRectMake(10, 10, 300, 40);
[button addTarget:self action:@selector(changeUIView1) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:button];
UIButton *button2 = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[button2 setTitle:@"改变2" forState:UIControlStateNormal];
button2.frame = CGRectMake(10, 120, 300, 40);
[button2 addTarget:self action:@selector(changeUIView2) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:button2];
}
-(void) changeUIView1{
[UIView beginAnimations:@”animation” context:nil];
[UIView setAnimationDuration:1.0f];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[UIView setAnimationTransition:UIViewAnimationTransitionCurlDown forView:self.view cache:YES];
[self.view exchangeSubviewAtIndex:1 withSubviewAtIndex:0 ];
[UIView commitAnimations];
}
-(void) changeUIView2{
CATransition *transition = [CATransition animation];
transition.delegate = self;
transition.duration = 2.0f;
transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseIn];
transition.type = kCATransitionPush;
transition.type = @”pageCurl” ;//另一种设置动画效果方法
transition.subtype = kCATransitionFromBottom;
[self.view exchangeSubviewAtIndex:1 withSubviewAtIndex:0];
[self.view.layer addAnimation:transition forKey:@”animation”];
}
调用CATransition需要在frameworks中添加QuartzCore.framework,在.h文件中加入 #import