#import "ViewController.h"
@interface ViewController ()
@property(nonatomic,strong)UIView *simpleView;
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
//oc有垃圾回收机制 ios没有垃圾回收机制
_simpleView=[[UIView alloc]initWithFrame:CGRectMake(100, 100, 100, 100)];
_simpleView.backgroundColor=[UIColor magentaColor];
[self.view addSubview:_simpleView];
//设置边框
_simpleView.layer.borderColor=[UIColor yellowColor].CGColor;
}
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
//关键帧动画
CAKeyframeAnimation *keyA=[CAKeyframeAnimation animationWithKeyPath:@"position"];
//准备路径
CGPoint p1=CGPointMake(100, 100);
CGPoint p2=CGPointMake(200, 200);
CGPoint p3=CGPointMake(50, 120);
CGPoint p4=CGPointMake(300, 20);
CGPoint p5=CGPointMake(10, 20);
//将结构体转化成对象类型,用于存放到数组中作为关键帧
NSValue *v1=[NSValue valueWithCGPoint:p1];
NSValue *v2=[NSValue valueWithCGPoint:p2];
NSValue *v3=[NSValue valueWithCGPoint:p3];
NSValue *v4=[NSValue valueWithCGPoint:p4];
NSValue *v5=[NSValue valueWithCGPoint:p5];
//设定关键帧
keyA.values=@[v1,v2,v3,v4,v5];
//设置动画间隔
keyA.duration=4;
//添加动画
// [self.simpleView.layer addAnimation:keyA forKey:@"key"];
//设置什么,就将关键字写成下面方法的属性
//创建CABasicAnimation 动画并设定变换的属性
CABasicAnimation *ba=[CABasicAnimation animationWithKeyPath:@"transform.rotation"];
//设定变化初始值
ba.fromValue=@0;
//设定变化结束值
ba.toValue=@(M_PI_4*2);
//设置动画间隔
ba.duration=4;
//添加动画到视图的layer层
[self.simpleView.layer addAnimation:ba forKey:@"hehe"];
//因为CA动画结束后会回到起始位置,可以使用延时器将试图固定在目标状态
// [self performSelector:@selector(makeNewView) withObject:nil afterDelay:4];
//组装动画
CAAnimationGroup *group=[CAAnimationGroup animation];
//设置同时执行的动画的数组
group.animations=@[keyA,ba];
group.duration=4;
// [self.simpleView.layer addAnimation:group forKey:@"group"];
//CATransaction
//@"cube" @"moveIn" @"reveal" @"fade"(default) @"pageCurl" @"pageUnCurl" @"suckEffect" @"rippleEffect" @"oglFlip"
/**
* enum AnimationType:Int {
case Fade = 1, //淡入淡出
Push, //推挤
Reveal, //揭开
MoveIn, //覆盖
Cube, //立方体
SuckEffect, //吮吸
OglFlip, //翻转
RippleEffect, //波纹
PageCurl, //翻页
PageUnCurl, //反翻页
CameraIrisHollowOpen, //开镜头
CameraIrisHollowClose, //关镜头
CurlDown, //下翻页
CurlUp, //上翻页
FlipFromLeft, //左翻转
FlipFromRight //右翻转
}
*/
CATransition *transtion=[CATransition animation];
//设置动画类型
transtion.type=@"CameraIrisHollowClose";
//设置动画间隔
transtion.duration=4;
//设置动画路径
// transtion.subtype=kCATransitionFromLeft;
//添加动画
// [self.simpleView.layer addAnimation:transtion forKey:@"transtion"];
}
-(void)makeNewView{
_simpleView.transform=CGAffineTransformMakeRotation(M_PI_4);
//移除动画
[self.simpleView.layer removeAnimationForKey:@"1"];
}