iOS抽奖转盘动画之CAKeyFrame关键帧动画

上面的代码保持不变,依然是:

- (void)viewDidLoad {

    [super viewDidLoad];

    //创建一个图层

    CALayer *layer = [CALayer layer];

    //设置layerbounds  以自己为中心的坐标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];

}



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值