CABasicAnimation unlimited repeat without HUGE_VALF?

旧时模样 提交于 2019-12-03 08:08:33

问题


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?


回答1:


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



回答2:


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")


来源:https://stackoverflow.com/questions/7082578/cabasicanimation-unlimited-repeat-without-huge-valf

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!