1
votes

I'm trying to do a simple animation with 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"];



}

When I run this nothing is happen, furthermore when I send layer to the NSTextField instance it returns null as per the NSlog statement. This code is from a iOS example using UILabel as opposed NSTextField...could this be the problem?

My output is

2013-09-08 07:12:17.314 Allocator[646:303] The layer is (null) 2013-09-08 07:12:17.315 Allocator[646:303] Testfield exists and is of type: NSTextField

1
Is [self testTextField] nil? You might have forgotten to hook it up. - Kurt Revis
@KurtRevis The textfield is hooked up. I updated my question to show this and included my output. - Cory

1 Answers

0
votes

Found this SO Answer and realized I had to setWantsLayer:YES for the view, so I added

[[self testTextField] setWantsLayer:YES];

to awakeFromNib and all is working