Cocoa NSTextField动画

Cocoa NSTextField动画,cocoa,core-animation,Cocoa,Core Animation,我正在尝试用NSTextField制作一个简单的动画 - (void)bounceTimeLabel { // Create a key frame animation CAKeyframeAnimation *bounce = [CAKeyframeAnimation animationWithKeyPath:@"transform"]; // Create the values it will pass through CATransform3

我正在尝试用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。这段代码来自一个使用UILabel而不是NSTextField的iOS示例…这可能是问题所在吗

我的输出是

2013-09-08 07:12:17.314分配器[646:303]该层为空 2013-09-08 07:12:17.315分配器[646:303]测试字段存在且类型为:NSTextField

发现此问题并意识到我必须为视图设置WANTSLayer:是,因此我添加了

   - (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"];



}
[[self testTextField] setWantsLayer:YES];

要从NIB中唤醒并且所有功能都在工作,

是否[self testTextField]为零?你可能忘了把它连接起来。@KurtRevis文本字段已经连接好了。我更新了我的问题以显示这一点,并包含了我的输出。