1

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 が返されます。このコードは、NSTextField ではなく UILabel を使用する iOS の例からのものです...これが問題になる可能性はありますか?

私の出力は

2013-09-08 07:12:17.314 Allocator[646:303] レイヤーは (null) です 2013-09-08 07:12:17.315 Allocator[646:303] テストフィールドが存在し、タイプは NSTextField です

4

1 に答える 1

0

this SO Answerを見つけて、ビューにWantsLayer:YESを設定する必要があることに気付いたので、追加しました

[[self testTextField] setWantsLayer:YES];

awakeFromNibにすると、すべてが機能しています

于 2013-09-08T15:30:46.467 に答える