CocoaDev

Edit AllPages

There are a couple of tips on the site for dealing with fade-in/out effects for windows, but the trick seems to be a bit more difficult for NSView’s. FadeAViewAndItsContents has one option, but it requires creating a helper NSWindow object to hold the NSView in question. In my particular app, I want to fade a view in and out of visibility when the app is in full screen mode (think: QuickTime’s controller when you’re watching a movie full screen). Using a helper NSWindow wasn’t an option since only one window can appear at the CGShieldingWindowLevel(). The helper wouldn’t be visible.

So I came up with a little category on NSView that does the trick nicely, albeit in Tiger only. The code fails gracefully in my build environment since I build separate Panther and Tiger versions for other reasons. It should be possible to add runtime checks to make the code work in a unified build for both OS’s, but I haven’t added it at this point. Any additions would of course be welcome.

NSView+Fade.h:

#import <Cocoa/Cocoa.h>

@interface NSView(Fade)

NSView+Fade.m:

#import “NSView+Fade.h”

/** A category on NSView that allows fade in/out on setHidden: */ @implementation NSView(Fade) /** Hides or unhides an NSView, making it fade in or our of existance. @param hidden YES to hide, NO to show @param fade if NO, just setHidden normally. */

} @end

The above code is placed in the public domain if anyone cares to use it.


See also AMViewAnimation. –!Andy :) —-