禁用CATextLayer.string属性的隐式动画 [英] Disable Implicit Animation of CATextLayer.string Property

查看:341
本文介绍了禁用CATextLayer.string属性的隐式动画的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have a view with one sublayer of type CATextLayer. I override the views drawRect: method and in there change the CATextLayer.string property to an instance of NSAttributedString. Each time the NSAttributedString has the same text but with different colors. As of now each time the string property changes, the text color makes an animated transition into the new color.

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

Is there any way I can disable the animation of this property?

推荐答案

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

Figured it out, using the answer for this question: Disabling implicit animations in -[CALayer setNeedsDisplayInRect:]

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

In my particular case, to stop the changing of the CATextLayer.string property from being animated, this code was enough:

NSDictionary *newActions = [[NSDictionary alloc] initWithObjectsAndKeys:[NSNull null], @"contents", nil];
textLayer.actions = newActions;
[newActions release];

换句话说,似乎内容键禁用对 CATextLayer.string 属性更改的动画。

In other words, it seems that the contents key disables animations on changes to the CATextLayer.string property.

这篇关于禁用CATextLayer.string属性的隐式动画的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆