Что приводит к применению белой границы на NSProgressIndicator, отображаемый в системном меню?

StackOverflow https://stackoverflow.com/questions/2714951

Вопрос

Это то, что происходит, когда я создаю 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];
Это было полезно?

Решение

Не масштабируется 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..

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top