5

NSProgressIndicator を作成し、アクションの実行中にメソッドを使用NSStatusItem-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];
4

2 に答える 2

6

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
于 2010-05-13T18:45:42.690 に答える