システムメニューに表示されるnsprogressindicatorに白い境界線が適用される原因は何ですか?
-
01-10-2019 - |
質問
これは、私がnsprogressIndicatorを作成したときに起こることです 使用する NSStatusItem
's -setView:
方法 アクションを実行している間にメノバーエリアに表示するには:
混乱したnsprogressindicator http://cl.ly/l9r/contentの例
この境界線を表示する原因は何ですか?どうすれば削除できますか?意図した結果は、コントロールが透明であることです。
これが私が使用しているコードです:
NSProgressIndicator *progressIndicator = [[NSProgressIndicator alloc] init];
[progressIndicator setBezeled: NO];
[progressIndicator setStyle: NSProgressIndicatorSpinningStyle];
[progressIndicator setControlSize: NSSmallControlSize];
[progressIndicator sizeToFit];
[progressIndicator startAnimation: self];
[statusItem setView: progressIndicator]; // statusItem is an NSStatusItem instance
...
[statusItem setView: nil];
[progressIndicator stopAnimation: self];
[progressIndicator release];
解決
スケーリングしないでください NSProgressIndicator
それもですが NSView
. 。正常にサイズを変更する新しいビューを作成し、そのビューにステータスインジケーターを配置し、囲いのビューをに渡します -[NSStatusItem setView:]
. 。これが私の実装です。
の NSStatusItem+AnimatedProgressIndicator.m
,
- (void) startAnimation {
NSView *progressIndicatorHolder = [[NSView alloc] init];
NSProgressIndicator *progressIndicator = [[NSProgressIndicator alloc] init];
[progressIndicator setBezeled: NO];
[progressIndicator setStyle: NSProgressIndicatorSpinningStyle];
[progressIndicator setControlSize: NSSmallControlSize];
[progressIndicator sizeToFit];
[progressIndicator setUsesThreadedAnimation:YES];
[progressIndicatorHolder addSubview:progressIndicator];
[progressIndicator startAnimation:self];
[self setView:progressIndicatorHolder];
[progressIndicator center];
[progressIndicator setNextResponder:progressIndicatorHolder];
[progressIndicatorHolder setNextResponder:self];
}
- (void) stopAnimation {
[self setView:nil];
}
- (void) mouseDown:(NSEvent *) theEvent {
[self popUpStatusItemMenu:[self menu]];
}
- (void) rightMouseUp:(NSEvent *) theEvent {}
- (void) mouseUp:(NSEvent *) theEvent {}
…
カスタムメソッドを追加しました、 -[NSView center]
, 、次のことを行います。
@implementation NSView (Centering)
- (void) center {
if (![self superview]) return;
[self setFrame:NSMakeRect(
0.5 * ([self superview].frame.size.width - self.frame.size.width),
0.5 * ([self superview].frame.size.height - self.frame.size.height),
self.frame.size.width,
self.frame.size.height
)];
}
@end
他のヒント
私があなたが私が残す問題を解決したのを見てきましたこれはあなたの実装に代わるものです。使用できます Progresshud.
所属していません StackOverflow