您的位置:首页 > 移动开发 > IOS开发

iOS抽奖转盘动画之CAAnimation动画

2015-10-10 14:00 316 查看
/*CAAnimation

1.基础动画 CABasicAnimation

2.关键帧动画 CAKeyframeAnimation

3.转场动画 CATransition

4.动画组 CAAnimationGroup

*/

导入QuartzCore 头文件 和库

@interface
ViewController ()

//声明一个图层的属性

@property (nonatomic,strong) CALayer *layer;

@end

@implementation ViewController

- (void)viewDidLoad {

[superviewDidLoad];

//创建一个图层

CALayer *layer = [CALayerlayer];

//设置layer的bounds 以自己为中心的坐标x,y都是00

layer.bounds =
CGRectMake(0,
0, 100, 100);

//相对superlayer的位置

layer.position =
CGPointMake(100,
100);

// layer.anchorPoint = CGPointMake(0, 0);
锚点和position是不同坐标系下的同一个位置

layer.backgroundColor = [UIColoryellowColor].CGColor;

//添加到视图的图层上

[self.view.layeraddSublayer:layer];

//赋值给自己的layer属性

self.layer = layer;

}

//通过触摸的方式演示动画

- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{

[selfanimationScale];

}

- (void)animationScale{

//1.创建动画对象 通过类方法创建

CABasicAnimation *anim = [CABasicAnimationanimation];

//2.设置动画 :keyPath 决定了执行怎样的动画执行大小变化的动画

// anim.keyPath = @"backgroundColor";

anim.keyPath =
@"bounds";

//bounds对应的是缩放 position对应的是平移 transform对应的是旋转

//tovalue是到达哪个点 byValue从增加多少值 fromValue 从哪个点开始移动

// anim.toValue = [NSValue valueWithCGRect:CGRectMake(0, 0, 50, 50)];

/*创建一个矢量

anim.toValue = [NSValue valueWithCGVector:CGVectorMake(100, 100)];

*/

anim.toValue = [NSValuevalueWithCGRect:CGRectMake(0,0,50,
50)];

//动画执行时间

anim.duration =
3.0f;

//动画执行完毕后不移除动画

anim.removedOnCompletion =YES;//如果设置为NO 那么就要设置fillMode来规定动画结束后的状态

//动画状态 决定当前动画在非active时间段的行为 比如动画开始之前动画结束之后

// anim.fillMode = @"forwards";

//3.添加动画到图层上 key是用来标识动画的,应该是唯一的即使是nil

[self.layeraddAnimation:animforKey:nil];

}

- (void)didReceiveMemoryWarning {

[superdidReceiveMemoryWarning];

}

@end
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: