我试着用NSTextField做一个简单的动画
- (void)bounceTimeLabel
{
// Create a key frame animation
CAKeyframeAnimation *bounce =
[CAKeyframeAnimation animationWithKeyPath:@"transform"];
// Create the values it will pass through
CATransform3D forward = CATransform3DMakeScale(1.3, 1.3, 1);
CATransform3D back = CATransform3DMakeScale(0.7, 0.7, 1);
CATransform3D forward2 = CATransform3DMakeScale(1.2, 1.2, 1);
CATransform3D back2 = CATransform3DMakeScale(0.9, 0.9, 1);
[bounce setValues:[NSArray arrayWithObjects:
[NSValue valueWithCATransform3D:CATransform3DIdentity],
[NSValue valueWithCATransform3D:forward],
[NSValue valueWithCATransform3D:back],
[NSValue valueWithCATransform3D:forward2],
[NSValue valueWithCATransform3D:back2],
[NSValue valueWithCATransform3D:CATransform3DIdentity],
nil]];
// Set the duration
[bounce setDuration:0.6];
// Animate the layer
NSLog(@"The layer is %@", [[self testTextField] layer]);
if (![self testTextField]) {
NSLog(@"Textfeild is nil");
} else {
NSLog(@"Testfield exists and is of type: %@", [[self testTextField] class]);
}
[[[self testTextField] layer] addAnimation:bounce
forKey:@"bounceAnimation"];
}当我运行时,不会发生任何事情,而且,当我向NSTextField实例发送层时,它会按照NSlog语句返回null。这段代码来自一个iOS示例,它使用的是UILabel而不是NSTextField...could,这是问题所在吗?
我的输出是
2013年-09-08:12:17.314分配程序646:303层为(空) 2013-09-08 07:12:17.315分配程序646:303Testfield类型: NSTextField
发布于 2013-09-08 15:30:46
找到这个SO Answer,意识到我必须设置setWantsLayer:是的,所以我添加了
[[self testTextField] setWantsLayer:YES];到awakeFromNib和所有的都在工作
https://stackoverflow.com/questions/18675539
复制相似问题