我正在尝试用 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"];
}
当我运行它时,什么都没有发生,此外,当我将 layer 发送到 NSTextField 实例时,它根据 NSlog 语句返回 null 。此代码来自使用 UILabel 而不是 NSTextField 的 iOS 示例......这可能是问题吗?
我的输出是
2013-09-08 07:12:17.314 Allocator[646:303] 层为(空) 2013-09-08 07:12:17.315 Allocator[646:303] 测试字段存在且类型为:NSTextField