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?
Asked
Active
Viewed 2.7k times
43
-
The value is `1e50`, in `math.h`. – bcattle Jun 25 '14 at 00:02
-
In XCode ⌘-click to go to the definition of something. – bcattle Jun 25 '14 at 00:08
2 Answers
143
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

jtbandes
- 115,675
- 35
- 233
- 266
-
in iOS 7 and above , it stops after certain interval.Not sure whats the reason though. – SRP-Achiever Aug 20 '14 at 18:04
-
`Float.infinity` in Swift. Referred docs mention `HUGE_VALF` but doesn't tell how to express same in Swift. – Valeriy Van Aug 04 '15 at 21:17
7
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")

Hiren Panchal
- 2,963
- 1
- 25
- 21