views:

189

answers:

2

Hey guys,

I want to know if I can slowly increase the alpha MainWindow when I open the app and when I close the app. I know it may involve timers, and things like that, but I never dealt with this kind of thing before. I need your help guys...!

Kevin

+1  A: 

[self setAlphaValue:0];

That'll set the alpha of the window. Just create an NSTimer that either adds or subtracts to bring the alpha up or down. The Value is an <#(CGFloat)windowAlpha#>.

Matt S.
I get this error, when I use setAlphaValue... Can you show me step by step how to do this?
Kevin
the code I'm using is: - (id)initWithContentRect:(NSRect)contentRect styleMask:(unsigned int)aStyle backing:(NSBackingStoreType)bufferingType defer:(BOOL)flag { if ((self = [super initWithContentRect:contentRect styleMask:NSBorderlessWindowMask backing:NSBackingStoreBuffered defer:NO])) { //[self setAlphaValue:0]; // Turn off opacity so that the parts of the window that are not drawn into are transparent. [self setOpaque:NO]; //place any further initialization you need here } return self;}
Matt S.
sorry it's so messy :(
Matt S.
yea it is... it is a bit confusing.. do I just put this all in one line? And how would I interpret this in NSTimer as well. I want my app to go from 0 alpha to 100 slolwy
Kevin
it's multiple lines, it just didn't format correctly. To add an NSTimer all you have to do is initialize it (in the .h) then in the .m just add this line to awakefromnib: timer = [NSTimer scheduledTimerWithTimeInterval:(1.0) target:self selector:@selector(onTimer) userInfo:nil repeats:YES]; timer=timername onTimer=the thing to call, 1.0=1 sec. Then on the call simply have it add one to an int then on setAlphaValue set that to the int (also include a check to see if it goes over 100, you don't want it to waste memory)
Matt S.
You do not want to set the alpha to 100, as it's a multiplier, not a percentage.
Peter Hosey
oh yea, forgot to mention that one
Matt S.
+3  A: 

Use NSViewAnimation. Despite the name, it works on windows as well as views.

Peter Hosey