プロジェクトで 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++;
}