禁用CATextLayer.string属性的隐式动画

Ant*_*oni 4 animation layer ios

我有一个CATextLayer类型的子层视图.我覆盖了视图drawRect:方法,并在那里将CATextLayer.string属性更改为NSAttributedString的实例.每次NSAttributedString具有相同的文本但具有不同的颜色.截至目前,每次字符串属性更改时,文本颜色都会将动画过渡到新颜色.

有什么办法可以禁用这个属性的动画吗?

Ant*_*oni 7

想出来,使用这个问题的答案: 在 - [CALayer setNeedsDisplayInRect:]中禁用隐式动画

在我的特殊情况下,要停止更改CATextLayer.string属性的动画,这段代码就足够了:

NSDictionary *newActions = [[NSDictionary alloc] initWithObjectsAndKeys:[NSNull null], @"contents", nil];
textLayer.actions = newActions;
[newActions release];
Run Code Online (Sandbox Code Playgroud)

换句话说,似乎该contents键禁用了对CATextLayer.string属性更改的动画.