Animation的基本实现功能:
首先创建一个简单的button 在button方法中来实现不同的动画效果:
- (void)buttonClicked:(UIButton *)button
{
// UIView 动画
// 1.最简单的动画实现
// 参数1:动画执行一次需要的时间
// 参数2:动画执行的内容(写动画执行的结果)
// [UIView animateWithDuration:10.0 animations:^{
// button.alpha = 0.38;
// button.backgroundColor = [UIColor blueColor];
// button.frame = CGRectMake(0, 0, 320, 100);
// }];
// 参数3:动画执行结束后 要执行的代码
// [UIView animateWithDuration:1.f animations:^{
//
// // 对动画本身设置
//
// // 可以给动画一个还原效果
// [UIView setAnimationRepeatAutoreverses:YES];
// // 动画重复的次数
// [UIView setAnimationRepeatCount:1.25];
// // 动画延迟几秒执行
// // [UIView setAnimationDelay:1.0];
// // 动画运行的速度曲线
// [UIView setAnimationCurve:UIViewAnimationCurveEaseIn];
//
// button.backgroundColor = [UIColor blueColor];
// button.bounds = CGRectMake(0, 0, 200, 200);
// } completion:^(BOOL finished) {
// NSLog(@"动画完毕");
// }];
// 3.
// 参数3:动画的选项 在这里一般写 速度曲线
// [UIView animateKeyframesWithDuration:1.f delay:0 options:UIViewAnimationOptionCurveEaseIn animations:^{
// button.frame = CGRectMake(0, 0, 200, 200);
// } completion:nil];
//4.
// [UIView animateWithDuration:1.f delay:0 usingSpringWithDamping:0.05 initialSpringVelocity:0.4 options:UIViewAnimationOptionCurveEaseIn animations:^{
// button.frame = CGRectMake(0, 0, 200, 200);
// } completion:nil];
// transition动画
// [UIView transitionWithView:button duration:1.f options:UIViewAnimationOptionTransitionCurlDown animations:^{
// button.frame = CGRectMake(0, 0, 200, 200);
// } completion:nil];
// 把第一个视图移除 把第二个视图 添加到父视图上
// UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 200, 200)];
// view.backgroundColor = [UIColor blueColor];
// // 参数1;要移除的view
// // 参数2:要添加的view
// [UIView transitionFromView:button toView:view duration:1.f options:UIViewAnimationOptionTransitionCurlUp completion:^(BOOL finished) {
//
// }];
// CAAnimation layer层动画
// CAPropertyAnimation 是一个抽象类
// 1. CABasicAnimation 的使用
// CABasicAnimation *animation1 = [CABasicAnimation animationWithKeyPath:@"transform.scale.y"];
// // 从什么状态开始放大
// animation1.fromValue = [NSNumber numberWithInt:1];
// // 到什么状态结束
// animation1.toValue = [NSNumber numberWithInt:3];
// // 动画执行的时间
// animation1.duration = 1.f;
// // 是否有一个恢复
// animation1.autoreverses = YES;
// animation1.repeatCount = NSIntegerMax;
//
//
// CABasicAnimation *animation2 = [CABasicAnimation animationWithKeyPath:@"transform.rotation"];
//
// // 从什么状态开始放大
// animation2.fromValue = [NSNumber numberWithInt:1];
// // 到什么状态结束
// animation2.toValue = [NSNumber numberWithInt:M_PI * 2];
// // 动画执行的时间
// animation2.duration = 2.f;
// // 是否有一个恢复
animation2.autoreverses = YES;
// animation2.repeatCount = NSIntegerMax;
//
//
//
// // 组动画 将几个动画组合到一起 同时执行
//
// CAAnimationGroup *group = [CAAnimationGroup animation];
// group.animations = @[animation1,animation2];
// // 将动画 添加到组动画之后 每个动画自己的设置将失效
// group.duration = 3.f;
// group.autoreverses = YES;
// group.repeatCount = NSIntegerMax;
//
// [button.layer addAnimation:group forKey:@"111"];
//
//
//
// [button.layer addAnimation:animation2 forKey:@"111"];
// // 关键帧动画
// CAKeyframeAnimation *keyFrameAni = [CAKeyframeAnimation animationWithKeyPath:@"position"];
//
// // 产生一个路径
// CGMutablePathRef path = CGPathCreateMutable();
// // 设定一个初始点
// CGPathMoveToPoint(path, nil, 100, 100);
//
// // 添加一个路过的点(添加一条直线的路径)
// CGPathAddLineToPoint(path, NULL, 200, 100);
// CGPathAddLineToPoint(path, NULL, 300, 0);
// CGPathAddLineToPoint(path, NULL, 10, 200);
// CGPathAddLineToPoint(path, NULL, 30, 0);
// CGPathAddLineToPoint(path, NULL, 150, 40);
// CGPathAddLineToPoint(path, NULL, 300, 0);
//
//
// // 添加一条曲线路径
// CGPathAddCurveToPoint(path, NULL, 10, 20, 100, 300, 150, 100);
// CGPathAddCurveToPoint(path, NULL, 100, 150, 100, 0, 150, 100);
// CGPathAddCurveToPoint(path, NULL, 120, 230, 105, 542, 10, 10);
//
// // 设置路径信息
// [keyFrameAni setPath:path];
// // 设置执行时间
// [keyFrameAni setDuration:5.f];
//
// [button.layer addAnimation:keyFrameAni forKey:@"222"];
// 过渡 变形
// CATransition *transition = [CATransition animation];
//
// // 过渡动画CATransition 依靠type/subType改变动画效果
// transition.duration = 2.f;
//
// // 动画类型
// //[transition setType:kCATransitionMoveIn];
// [transition setType:@"cameraIrisHollowClose"];
// // 动画方向
// [transition setSubtype:kCATransitionFromLeft];
//
// [button.layer addAnimation:transition forKey:@"333"];
}