Lo que hace que un borde blanco que se aplica a un NSProgressIndicator representada en el menú del sistema?

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

Pregunta

Esto es lo que sucede cuando creo una NSProgressIndicator y método NSStatusItem uso de -setView: para mostrarla en el área de la barra de menú mientras estoy realizando una acción:

Ejemplo de mal estado NSProgressIndicator http://cl.ly/l9R/content

Lo que hace que esta frontera que se mostrará, y cómo puedo eliminarlo? El resultado deseado es que el control sea transparente.

Aquí está el código que estoy usando:

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];
¿Fue útil?

Solución

No cambia la escala del NSProgressIndicator aunque es también un NSView. Crear una nueva vista que cambia de tamaño fino, la posición del indicador de estado en ese punto de vista, y pasar el punto de vista de cerramiento a -[NSStatusItem setView:]. Aquí está mi aplicación.

En 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 {}
…

He añadido un método personalizado, -[NSView center], que hace lo siguiente:

@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

Otros consejos

he visto que resolvió el problema voy a dejar esta es una alternativa a su aplicación. Puede usar ProgressHud .

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top