我正在尝试使用 CABasicAnimation 自动重复我的图像旋转动画。我试图在网上搜索如何设置此类属性,但无法找到。CA动画真的没有这样的属性吗?我知道您可以为 repeatCount 属性设置一些巨大的值(此处),但是,嘿,为什么 UIView animateWithDuration 有一个选项 UIViewAnimationOptionRepeat 以及为它硬编码的值是什么?
问问题
25575 次
2 回答
7
对于 swift 3.0 及以上版本
let rotationAnimation = CABasicAnimation(keyPath: "transform.rotation.z")
rotationAnimation.fromValue = 0
rotationAnimation.toValue = CGFloat.pi * 2
rotationAnimation.duration = 1
rotationAnimation.repeatCount = .infinity
holderView.btnRefresh.layer.add(rotationAnimation, forKey: "spinAnimation")
于 2017-04-19T10:41:00.167 回答