NSStatusItem オブジェクトにカスタム ビューがあります。このビューにはアイコンが表示されます。進行状況を表示することもできますが、[self.statusitemview setProgressValue:theValue];
I have a set of icons を呼び出す必要があり、この値を使用して適切なアイコンを選択します。
実行されたプロセスが常に更新を送信するわけではないため、これは非常にぎくしゃくしています。だからこれをアニメ化したい。
他のココア コントロールと同じようにアニメーションを呼び出したいと思います: [[self.statusItemView animator] setProgressValue:value];
もしそれが可能なのであれば
これを行う適切な方法は何ですか?NSTimer は使いたくありません。
編集
画像は drawRect: メソッドを使用して描画されます
コードは次のとおりです。
- (void)drawRect:(NSRect)dirtyRect
{
if (self.isHighlighted) {
[self.statusItem drawStatusBarBackgroundInRect:self.bounds withHighlight:YES];
}
[self drawIcon];
}
- (void)drawIcon {
if (!self.showsProgress) {
[self drawIconWithName:@"statusItem"];
} else {
[self drawProgressIcon];
}
}
- (void)drawProgressIcon {
NSString *pushed = (self.isHighlighted)?@"-pushed":@"";
int iconValue = ((self.progressValue / (float)kStatusItemViewMaxValue) * kStatusItemViewProgressStates);
[self drawIconWithName:[NSString stringWithFormat:@"statusItem%@-%d", pushed, iconValue]];
}
- (void)drawIconWithName:(NSString *)iconName {
if (self.isHighlighted && !self.showsProgress) iconName = [iconName stringByAppendingString:@"-pushed"];
NSImage *icon = [NSImage imageNamed:iconName];
NSRect drawingRect = NSCenterRect(self.bounds, icon);
[icon drawInRect:drawingRect fromRect:NSZeroRect operation:NSCompositeSourceOver fraction:1.0 respectFlipped:YES hints:nil];
}
- (void)setProgressValue:(int)progressValue {
if (progressValue > kStatusItemViewMaxValue || progressValue < 0) {
@throw [NSException exceptionWithName:@"Invalid Progress Value"
reason:[NSString stringWithFormat:@"The value %d id invalid. Range {0 - %d}", progressValue, kStatusItemViewMaxValue]
userInfo:nil];
}
_progressValue = progressValue;
[self setNeedsDisplay:YES];
}
- (void)setShowsProgress:(BOOL)showsProgress {
if (!showsProgress) self.progressValue = 0;
_showsProgress = showsProgress;
[self setNeedsDisplay:YES];
}
なんとかできるはずです。Apple の標準コントロールは drawRect: を使用して描画されるため、アニメーションはスムーズです...