淡化、推挤、揭开、覆盖
NSString * const kCATransitionFade;
NSString * const kCATransitionMoveIn;
NSString * const kCATransitionPush;
也有四种
NSString * const kCATransitionFromRight;
NSString * const kCATransitionFromLeft;
NSString * const kCATransitionFromTop;
[super viewDidLoad];
UIButton *btn1 = [UIButton buttonWithType:UIButtonTypeCustom];
btn1.frame = CGRectMake(50, 50, 100, 30);
//btn1.backgroundColor = [UIColor blackColor];
[btn1 setTitle:@"动画一" forState:UIControlStateNormal];
[btn1 setTitleColor:[UIColor greenColor] forState:UIControlStateNormal];
[btn1 addTarget:self action:@selector(btn1) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:btn1];
UIButton *btn2 = [UIButton buttonWithType:UIButtonTypeCustom];
btn2.frame = CGRectMake(120, 50, 100, 30);
[btn2 setTitle:@"动画二" forState:UIControlStateNormal];
[btn2 setTitleColor:[UIColor greenColor] forState:UIControlStateNormal];
[btn2 addTarget:self action:@selector(btn2) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:btn2];
UIButton *btn3 = [UIButton buttonWithType:UIButtonTypeCustom];
btn3.frame = CGRectMake(190, 50, 100, 30);
[btn3 setTitle:@"动画三" forState:UIControlStateNormal];
[btn3 setTitleColor:[UIColor greenColor] forState:UIControlStateNormal];
[btn3 addTarget:self action:@selector(btn3) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:btn3];
UIView *view = [[UIView alloc]initWithFrame:CGRectMake(375/2.0-50, 300, 100, 100)];
view.tag = 1;
view.backgroundColor = [UIColor greenColor];
[self.view addSubview:view];
}
-(void)btn1{
UIView *view = [self.view viewWithTag:1];
[UIView beginAnimations:@"1" context:nil];//创建动画
[UIView setAnimationCurve:UIViewAnimationCurveEaseIn];//动画曲线
[UIView setAnimationDelay:0];//延时动画
[UIView setAnimationDuration:2];//动画持续时间
[UIView setAnimationRepeatCount:2];//动画循环次数
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:view cache:YES];//设置动画效果,以及要执行的view(动画发生位置,此处是view)
[UIView setAnimationDelegate:self];//设置动画代理
[UIView setAnimationDidStopSelector:@selector(stop)];//动画结束后调用的方法,注意设置次方法之前要先设置代理
[UIView commitAnimations];//提交动画
}
-(void)btn2{
UIView *view = [self.view viewWithTag:1];
CATransition *ansition = [CATransition animation];//创建动画
ansition.duration = 2;//动画持续时间
//ansition.repeatCount = 2;//动画循环次数
ansition.type = @"cameraIrisHollowOpen";//设置动画类型
ansition.subtype = kCATransitionFromLeft;//设置动画方向
ansition.delegate = self;//设置动画代理
[view.layer addAnimation:ansition forKey:@"12"];//添加动画
}
-(void)btn3{
UIView *view = [self.view viewWithTag:1];
CGPoint center = view.center;
//放大效果
// [UIView animateWithDuration:1 animations:^{
// view.frame = CGRectMake(10, 10, 300, 300);
// view.center = center;
//
// }];
//放大缩小连续
[UIView animateWithDuration:1 animations:^{
view.frame = CGRectMake(10, 10, 300, 300);
view.center = center;
} completion:^(BOOL finished) {
[UIView animateWithDuration:1 animations:^{
view.frame = CGRectMake(375/2.0, 300, 100, 100);
view.center = center;
} completion:^(BOOL finished) {
[self btn3];//添加动画
}];
}];
//实现缩小和放大
view.frame = CGRectMake(10, 10, 300, 300);
view.center = center;
} completion:^(BOOL finished) {
[UIView animateWithDuration:1 animations:^{
view.frame = CGRectMake(375/2.0, 300, 100, 100);
view.center = center;
}completion:^(BOOL finished) {
[self btn3];
}];
}
-(void)stop1{
NSLog(@"动画停止");
}
-(void)animationDidStart:(CAAnimation *)anim{
NSLog(@"动画开始");