- (void)viewDidLoad {
[super viewDidLoad];
self.view.backgroundColor = [UIColor whiteColor];
UIButton *btn = [UIButton buttonWithType:UIButtonTypeSystem];
btn.frame = CGRectMake(100, 200, 100, 100);
btn.backgroundColor = [UIColor redColor];
[self.view addSubview:btn];
[btn setTitle:@"GoBack" forState:UIControlStateNormal];
[btn addTarget:self action:@selector(click:) forControlEvents:UIControlEventTouchUpInside];
}
-(void)click:(UIButton *)btn{
NSLog(@"~~~~动画~~~~~");
#if 0/* CABasicAnimation */
//position 位置
//rotation 旋转
//scale 缩放
//通过keyPath(建路径: 对象的属性也是属性, 通过获取属性中的属性)
CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"transform.scale"];
//持续时间
animation.duration = 1;
//起始状态
animation.fromValue = @(0.5);
//终止状态
animation.toValue = @(2);
//重复次数(默认为0)
animation.repeatCount = NSIntegerMax;
//自动恢复(默认为NO)
animation.autoreverses = YES;
//把动画添加给layer
// [btn.layer addAnimation:animation forKey:@"scale"];
CABasicAnimation *animation1 = [CABasicAnimation animationWithKeyPath:@"transform.rotation"];
animation1.duration = 2;
animation1.fromValue = @(0);
animation1.toValue = @(M_PI * 2);
animation1.repeatCount = NSIntegerMax;
animation1.autoreverses = YES;
// [btn.layer addAnimation:animation1 forKey:@"rotation"];
//组动画
CAAnimationGroup *group = [CAAnimationGroup animation];
//把动画添加到组中
group.animations = @[animation, animation1];
//重新设置动画组的属性
group.duration = 2;
group.repeatCount = NSIntegerMax;
[btn.layer addAnimation:group forKey:@"组动画"];
#endif
#if 0/* CAtransition */
CATransition *transition = [CATransition animation];
transition.duration = 2;
transition.repeatCount = NSIntegerMax;
//动画类型
//fade', `moveIn', `push' and `reveal'
/** type
*
* 各种动画效果 其中除了'fade', `moveIn', `push' , `reveal',其他属于私有的API.
* ↑↑↑上面四个可以分别使用'kCATransitionFade', 'kCATransitionMoveIn', 'kCATransitionPush', 'kCATransitionReveal'来调用.
* @"cube" 立方体翻滚效果
* @"moveIn" 新视图移到旧视图上面
* @"reveal"
显露效果(将旧视图移开,显示下面的新视图)
* @"fade" 交叉淡化过渡(不支持过渡方向) (默认为此效果)
* @"pageCurl" 向上翻一页
* @"pageUnCurl" 向下翻一页
* @"suckEffect" 收缩效果,类似系统最小化窗口时的神奇效果(不支持过渡方向)
* @"rippleEffect" 滴水效果,(不支持过渡方向)
* @"oglFlip" 上下左右翻转效果
* @"rotate" 旋转效果
* @"push"
* @"cameraIrisHollowOpen" 相机镜头打开效果(不支持过渡方向)
* @"cameraIrisHollowClose" 相机镜头关上效果(不支持过渡方向)
*/
/** type
*
* kCATransitionFade 交叉淡化过渡
* kCATransitionMoveIn 新视图移到旧视图上面
* kCATransitionPush 新视图把旧视图推出去
* kCATransitionReveal 将旧视图移开,显示下面的新视图
*/
transition.type = @"rippleEffect";
//动画方向
//kCATransitionFromRight kCATransitionFromLeft kCATransitionFromTop kCATransitionFromBottom
transition.subtype = kCATransitionFromRight;
[btn.layer addAnimation:transition forKey:@"go"];
// //组动画
// CAAnimationGroup *group = [CAAnimationGroup animation];
// //把动画添加到组中
// group.animations = @[animation, animation1, transition];
// //重新设置动画组的属性
// group.duration = 2;
// group.repeatCount = NSIntegerMax;
// [btn.layer addAnimation:group forKey:@"组动画"];
#endif
}