动画 CATextLayer 的 foregroundColor 属性
我想为 iPhone 上 CATextLayer 的文本颜色(前景色)的变化添加动画效果。根据文档,该属性的隐式动画在 OSX 10.6 上不可用,但没有提及 iOS。因此,我假设动画必须是明确的才能在 iOS 上运行。
我使用 +(class)layerClass
更改了支持层类,并在 UIView init
方法中为该属性设置了初始值。文本以及我应用的所有属性(阴影、字体等)显示得很好,但动画没有产生任何影响。
下面是我的动画方法,我从 KVO 观察方法调用该方法,以便视图在观察到的属性发生更改时提醒用户。
-(void) animateTextChange{
animation = [CABasicAnimation animationWithKeyPath:@"foregroundColor"];
[animation setFromValue:[[UIColor blackColor] CGColor]];
[animation setToValue:[[UIColor whiteColor] CGColor]];
[animation setDuration:2.0f];
[[self layer] addAnimation:animation
forKey:@"foregroundColor"
];
}
一如既往地感谢。
I want to animate the change in the color of text(foregroundColor) of a CATextLayer on the iPhone. According to the documentation, implicit animation of the property is not available on OSX 10.6, but no mention is made of iOS. As a result i've just assumed that the animation must be explicit for it to work on iOS.
I've changed the backing layer class using +(class)layerClass
, and set an initial value for the property in the UIView init
method. The text shows up just fine, along with all of the properties i've applied (shadow, font etc), yet the animation fails to have any impact.
Below is my animation method, that i call from a KVO observation method so that the view alerts the user when the observed property has changed.
-(void) animateTextChange{
animation = [CABasicAnimation animationWithKeyPath:@"foregroundColor"];
[animation setFromValue:[[UIColor blackColor] CGColor]];
[animation setToValue:[[UIColor whiteColor] CGColor]];
[animation setDuration:2.0f];
[[self layer] addAnimation:animation
forKey:@"foregroundColor"
];
}
Thanks as always.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是我成功做到这一点的唯一方法:
希望它能帮助别人
This is the only way i succeeded to do that:
Hope it will help someone