NSStatusItem在突出显示时绘制动画

时间:2013-03-25 07:46:09

标签: objective-c macos core-animation nsview nsstatusitem

我在我的项目中使用NSStatusItem,我想在程序运行时将其设置为动画。没有选择项目时,它可以正常工作。但是当我点击它时,图像就会冻结。我试图通过计时器设置备用图像,但没有结果。最新的想法是在我的NSStatusItem上绘制NSView,但也没有结果。

- (void)startAnimating
{
    currentFrame = 1;
    animTimer = [NSTimer scheduledTimerWithTimeInterval:1.0/15.0 target:self selector:@selector(updateImage:) userInfo:nil repeats:YES];
}

- (void)stopAnimating
{
    [animTimer invalidate];
}

- (void)updateImage:(NSTimer*)timer
{
    if (currentFrame == 13)
    {
        currentFrame = 1;
    }
    NSImage* image;
    if ([window backingScaleFactor] == 1.0)
    {
        image = [NSImage imageNamed:[NSString stringWithFormat:@"App_18_gr_%d",currentFrame]];
        NSRect rect = [[StatusItem view] frame];
        [image drawInRect:[[StatusItem view] frame] fromRect:NSZeroRect operation:NSCompositeSourceOver fraction:1.0];
        [image setTemplate:YES];
    }
    else
    {
        image = [NSImage imageNamed:[NSString stringWithFormat:@"App_36_gr_%d",currentFrame]];
        [image drawInRect:[[StatusItem view] frame] fromRect:NSZeroRect operation:NSCompositeSourceOver fraction:1.0];
        [image setTemplate:YES];
    }
    [StatusItem setImage:image];
    currentFrame++;
}

0 个答案:

没有答案