CABasicAnimation为何不重复执行动画?

weixin_37398652 2017-01-23 10:36:59
正学习CoreAnmimation,想要实现一个效果,某个图像缩小后变回原来大小,无限循环执行.代码如下:
let animation = CABasicAnimation(keyPath: "transform.scale")
animation.toValue = 0.5
animation.fromValue = 1
animation.duration = 2
animation.fillMode = "backwards"
rotationAnim.repeatCount = 3
animation.isRemovedOnCompletion = false
imageView.layer.add(animation, forKey: nil)
发现只执行一次.
...全文
711 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
weixin_41694952 2019-01-28
  • 打赏
  • 举报
回复
你需要将 animation.fillMode = "backwards" animation.isRemovedOnCompletion = false 去掉 然后 rotationAnim.repeatCount = HUGE_VALF 另外,推荐一款动画库:https://github.com/hon-key/ThinkVerb 写动画会变得很容易
scribbler 2017-01-23
  • 打赏
  • 举报
回复
OC代码

    UIView * animationView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 200, 200)];
    animationView.backgroundColor = [UIColor greenColor];
    [self.view addSubview:animationView];
    animationView.center = self.view.center;
    
    CABasicAnimation *animation = [CABasicAnimation animation];
    animation.keyPath = @"transform.scale";
    animation.duration = 1.0;
    animation.fromValue = @(1.0);
    animation.toValue = @(0.1);
    animation.autoreverses = YES;
    animation.repeatCount = HUGE_VALF;
    [animationView.layer addAnimation:animation forKey:nil];
scribbler 2017-01-23
  • 打赏
  • 举报
回复
引用 2 楼 weixin_37398652 的回复:
楼上你的这样写有用吗?
你认为呢
weixin_37398652 2017-01-23
  • 打赏
  • 举报
回复
楼上你的这样写有用吗?

29,028

社区成员

发帖
与我相关
我的任务
社区描述
主要讨论与iOS相关的软件和技术
社区管理员
  • iOS
  • 大熊猫侯佩
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧