14

how can i make my CAKeyframeAnimation have a never ending repeat count?

I tried animation.repeatCount = -1; but it only repeats once.

5 Answers5

41

You can also use

animation.repeatCount = INFINITY;

This is exactly the same as HUGE_VALF, but I prefer INFINITY as it speaks by itself.

Phil
  • 2,776
  • 2
  • 26
  • 26
26

Try animation.repeatCount = HUGE_VALF;

grivescorbett
  • 1,586
  • 1
  • 20
  • 27
7

From the documentation for the CAMediaTiming protocol:

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

Tim
  • 57,767
  • 18
  • 155
  • 161
5

In Swift I'm using the following code:

let animation = CATransition()
animation.repeatCount = Float.infinity
Antoine
  • 21,544
  • 11
  • 81
  • 91
2

Just go to definition!
There is no matter what it will be: either HUGE_VALF or INFINITY.
Because:

(math.h:)

#if defined(__GNUC__)
#   define    HUGE_VAL     __builtin_huge_val()
#   define    HUGE_VALF    __builtin_huge_valf()
#   define    HUGE_VALL    __builtin_huge_vall()
#   define    NAN          __builtin_nanf("0x7fc00000")
#else
#   define    HUGE_VAL     1e500
#   define    HUGE_VALF    1e50f
#   define    HUGE_VALL    1e5000L
#   define    NAN          __nan()
#endif

#define INFINITY    HUGE_VALF

and finally (according to math.c):

/* FUNCTION: __builtin_huge_valf */   
inline float __builtin_huge_valf(void) { return 1.0f/0.0f; }

So each option will be ok:

animation.repeatCount = INFINITY;
animation.repeatCount = HUGE_VALF;
animation.repeatCount = __builtin_huge_valf();
animation.repeatCount = 1.0f/0.0f;