CABasicAnimation 无限重复而不使用 HUGE_VALF?

发布于 2024-11-30 06:54:21 字数 341 浏览 2 评论 0原文

我正在尝试使用 CABasicAnimation 执行图像旋转动画的自动重复。我试图在网上搜索如何设置此类属性,但无法找到。 CA动画真的没有这个属性吗?我知道您可以设置一些巨大的值(这里)重复计数属性,但是嘿,为什么 UIView animateWithDuration 有一个选项 UIViewAnimationOptionRepeat 以及硬编码的值是什么?

I'm trying to perform auto repeat of my image rotation animation with CABasicAnimation. I have tried to search on web how to set such property but was unable to find that. Is it really no such property for CA animation? I know that you can set some huge value (here) to repeatCount property but hey, why then does UIView animateWithDuration has an option UIViewAnimationOptionRepeat and what the value is hardcoded for it?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

奈何桥上唱咆哮 2024-12-07 06:54:21

不,这是您应该按照 文档

将此属性设置为 HUGE_VALF 将导致动画永远重复。


Swift 更新

HUGE_VALF 未向 Swift 公开。然而,我从此页面的理解是 HUGE_VALF 应该是无穷大(事实上,< code>INFINITY 定义为 HUGE_VALF)。由于 Swift 的 FloatingPointType 协议提供了 static var infinity,因此您可以简单地编写

myAnimation.repeatCount = .infinity

No, this is the way you're supposed to do it according to the documentation.

Setting this property to HUGE_VALF will cause the animation to repeat forever.


Update for Swift:

HUGE_VALF is not exposed to Swift. However, my understanding from this page is that HUGE_VALF is intended to be infinity (in fact, INFINITY is defined as HUGE_VALF). Since Swift's FloatingPointType protocol provides a static var infinity, you can simply write

myAnimation.repeatCount = .infinity
玻璃人 2024-12-07 06:54:21

适用于 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")

For swift 3.0 and above

              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")
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文