문제

I've got an NSButton called _indicatorButton with a PNG image (basically a green LED light as PNG set with setImage:) without border and text. I'm trying to make it "flash" with the following code:

- (void)animateButton
{
    NSLog(@"Animating…");
    CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"opacity"];
    [animation setFromValue:[NSNumber numberWithFloat:1.0]];
    [animation setToValue:[NSNumber numberWithFloat:0.0]];
    [animation setDuration:0.3f];
    [animation setTimingFunction:[CAMediaTimingFunction
                                  functionWithName:kCAMediaTimingFunctionEaseInEaseOut]];
    [animation setAutoreverses:YES];
    [animation setRepeatCount:20000];

    [_indicatorButton.layer addAnimation:animation forKey:@"opacity"];
}

…but nothing happens. The method gets called and the link in the XIB is OK, since changing the image on the button programmatically works fine.

Any hints why it doesn't blink at all?

도움이 되었습니까?

해결책

For backwards compatibility, views on OS X don't use Core Animation layers as their backing store by default. The reason nothing is happening is likely that layer of your button is nil.

You can tell your view that it should be layer-backed using myView.wantsLayer = YES;. Please read the documentation for wantsLayer.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top