14

我怎样才能让我CAKeyframeAnimation有一个永无止境的重复计数?

我试过animation.repeatCount = -1;但它只重复一次。

4

5 回答 5

41

你也可以使用

animation.repeatCount = INFINITY;

这与 HUGE_VALF 完全相同,但我更喜欢 INFINITY,因为它自己说话。

于 2011-02-21T15:26:20.750 回答
26

尝试animation.repeatCount = HUGE_VALF;

于 2011-01-03T00:40:33.140 回答
7

CAMediaTiming协议的文档中:

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

于 2011-01-03T00:42:38.147 回答
5

在 Swift 中,我使用以下代码:

let animation = CATransition()
animation.repeatCount = Float.infinity
于 2016-05-31T10:29:11.800 回答
2

只要去定义!
不管它是什么:HUGE_VALF 或 INFINITY。
因为:

(数学.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

最后(根据 math.c):

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

所以每个选项都可以:

animation.repeatCount = INFINITY;
animation.repeatCount = HUGE_VALF;
animation.repeatCount = __builtin_huge_valf();
animation.repeatCount = 1.0f/0.0f;
于 2014-12-25T15:56:05.093 回答