iOS抽奖转盘动画之CAKeyFrame关键帧动画
2015-10-10 18:04
363 查看
上面的代码保持不变,依然是:
- (void)viewDidLoad {
[super
viewDidLoad];
//创建一个图层
CALayer *layer = [CALayer
layer];
//设置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 = [UIColor
yellowColor].CGColor;
//添加到视图的图层上
[self.view.layer
addSublayer:layer];
//赋值给自己的layer属性
self.layer = layer;
}
//通过触摸的方式演示动画
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
// [self animationScale];
基础动画
[self
keyAnimation];//关键帧动画
}
下面是实现的关键帧动画函数
//关键帧动画
- (void)keyAnimation{
//1.创建动画对象并设置
让图层沿着圆形运动
CAKeyframeAnimation *anim = [CAKeyframeAnimation
animationWithKeyPath:@"position"];
anim.removedOnCompletion =
NO;//动画结束后不移除
anim.fillMode =
kCAFillModeForwards;//动画状态保持为最后的状态
也就是说状态保持不变
anim.duration =
3.0f;//动画时间3秒
// anim.repeatCount = 2;//动画重复次数2次
// anim.repeatDuration = 2.0f;//重复时间间隔2秒
//创建一个可变路径
CGMutablePathRef path =
CGPathCreateMutable();
//第二个参数为NULL
不进行变换
CGPathAddEllipseInRect(path,
NULL,
CGRectMake(100,
100,
200, 200));
anim.path = path;
//设置动画执行的节奏
anim.timingFunction = [CAMediaTimingFunction
functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
[self.layer
addAnimation:anim forKey:nil];
}
- (void)viewDidLoad {
[super
viewDidLoad];
//创建一个图层
CALayer *layer = [CALayer
layer];
//设置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 = [UIColor
yellowColor].CGColor;
//添加到视图的图层上
[self.view.layer
addSublayer:layer];
//赋值给自己的layer属性
self.layer = layer;
}
//通过触摸的方式演示动画
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
// [self animationScale];
基础动画
[self
keyAnimation];//关键帧动画
}
下面是实现的关键帧动画函数
//关键帧动画
- (void)keyAnimation{
//1.创建动画对象并设置
让图层沿着圆形运动
CAKeyframeAnimation *anim = [CAKeyframeAnimation
animationWithKeyPath:@"position"];
anim.removedOnCompletion =
NO;//动画结束后不移除
anim.fillMode =
kCAFillModeForwards;//动画状态保持为最后的状态
也就是说状态保持不变
anim.duration =
3.0f;//动画时间3秒
// anim.repeatCount = 2;//动画重复次数2次
// anim.repeatDuration = 2.0f;//重复时间间隔2秒
//创建一个可变路径
CGMutablePathRef path =
CGPathCreateMutable();
//第二个参数为NULL
不进行变换
CGPathAddEllipseInRect(path,
NULL,
CGRectMake(100,
100,
200, 200));
anim.path = path;
//设置动画执行的节奏
anim.timingFunction = [CAMediaTimingFunction
functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
[self.layer
addAnimation:anim forKey:nil];
}
相关文章推荐
- ios字符串操作
- iOS block 闭包的学习
- IOS 开发之 Method Swizzling + Category
- iOS7 监听耳机拔出
- ios 开发小记 (四)
- iOS:quartz2D绘图
- iOS学习之iOS沙盒(sandbox)机制和文件操作(一)
- iOS开发之保存照片到自己创建的相簿
- iOS 解析不规则json数据
- 头部拉伸效果(iOS)
- ios图片的合成
- ios 调试
- iOS开发相册使用
- ATS是什么
- iOS Git 返回以前提交的版本
- 适配iOS9(ATS问题)
- Use GraceNote SDK in iOS(一)通过序列化GDO查询专辑封面
- NSLog带颜色的日志输出
- iOS 系统报错收集
- ios之点语法