我怎样才能让我CAKeyframeAnimation
有一个永无止境的重复计数?
我试过animation.repeatCount = -1;
但它只重复一次。
我怎样才能让我CAKeyframeAnimation
有一个永无止境的重复计数?
我试过animation.repeatCount = -1;
但它只重复一次。
你也可以使用
animation.repeatCount = INFINITY;
这与 HUGE_VALF 完全相同,但我更喜欢 INFINITY,因为它自己说话。
尝试animation.repeatCount = HUGE_VALF;
从CAMediaTiming协议的文档中:
将此属性设置为
HUGE_VALF
将导致动画永远重复。
在 Swift 中,我使用以下代码:
let animation = CATransition()
animation.repeatCount = Float.infinity
只要去定义!
不管它是什么: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;