views:

306

answers:

1

I'm using Matt Gemmell's MAAttachedWindow (http://mattgemmell.com/source) with an NSStatusItem to display a custom view in the menu bar. I'm confused as to how to get it to fade in and fade out. Normally I'd do something like this:

[window makeKeyAndOrderFront:self];
[[window animator] setAlphaValue:1.0];

and to fade out:

[[window animator] setAlphaValue:0.0];

However this code seems to have no effect with MAAttachedWindow. Any ideas?

Thanks

+3  A: 

I'm not especially well versed in CoreAnimation and the usage of implicit animations. However, I was able to get the MAAttachedWindow to fade in by adding an explicit alphaValue property to the MAAttachedWindow class:

@interface MAAttachedWindow : NSWindow {
    CGFloat _alphaValue;
...
}
-(CGFloat) alphaValue;
-(void) setAlphaValue:(CGFloat)windowAlpha;
...

@implementation MAAttachedWindow

- (CGFloat) alphaValue {
 return _alphaValue;
}

- (void) setAlphaValue:(CGFloat)windowAlpha {
    _alpha = windowAlpha;
 [super setAlphaValue:windowAlpha];
}
...

By adding that, I was able to get the implicit animation for setAlphaValue to work:

(below code cribbed from Matt's Sample "NSStatusItemTest" code)

- (void)toggleAttachedWindowAtPoint:(NSPoint)pt
{
...
    [attachedWindow makeKeyAndOrderFront:self];
 [[attachedWindow animator] setAlphaValue:1.0];

I am not sure why explicitly defining the alphaValue property works. I would expect the inherited version from NSWindow would be invoked for the implicit animation. It doesn't appear to though.

Michael Lamb
Many thanks :-) Will try
macatomy
Works perfectly. Thanks again
macatomy