Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Darkroom

Guest
Original poster
Dec 15, 2006
2,445
0
Montréal, Canada
i'm attempting to fade my windows on quit, but the following code only seems to work if i have a custom quit method like -(IBAction)quitApp:(id)sender. i'm trying to override the applictionWillTerminate so the quit from the dock menu will also fade out windows, instead of abruptly quit. i know this new applicationWillTerminate method is getting called correctly because NSLog is outputting text before the app quits, but the fade out isn't being called. is it because this function is relying on a secondary funtion to complete it's task? how can i write it all in one function? any thoughts?

Code:
- (void)applicationWillTerminate:(NSNotification *)notification
	{
	NSLog (@"Application Terminate Override");
		
	SetSystemUIMode(kUIModeNormal, 0);
	timer = [[NSTimer scheduledTimerWithTimeInterval:0.02 target:self selector:@selector(allWindowsFadeOUT:) userInfo:nil repeats:YES] retain];
	}
	
- (void)allWindowsFadeOUT:(NSTimer *)theTimer
	{
	if (([mainWindow alphaValue] > 0.0) || ([secondWindow alphaValue] > 0.0)){
	[mainWindow setAlphaValue:[mainWindow alphaValue] - 0.1];
	[secondWindow setAlphaValue:[secondWindow alphaValue] - 0.1];
	}
	else
	{
	[timer invalidate];
	[timer release];
	timer = nil;
	[NSApp terminate:nil];
	}
}
 

Krevnik

macrumors 601
Sep 8, 2003
4,101
1,312
i'm attempting to fade my windows on quit, but the following code only seems to work if i have a custom quit method like -(IBAction)quitApp:(id)sender. i'm trying to override the applictionWillTerminate so the quit from the dock menu will also fade out windows, instead of abruptly quit. i know this new applicationWillTerminate method is getting called correctly because NSLog is outputting text before the app quits, but the fade out isn't being called. is it because this function is relying on a secondary funtion to complete it's task? how can i write it all in one function? any thoughts?

Yeah, the timer gets killed pretty much immediately after you create it.

Now first, my rant is that you probably shouldn't want to override the close behavior of the window. If someone is quitting your app, they want it gone. If your app lingers too long, then you get into a state where you could cancel restarts and shutdowns (bad).

That said, the easiest way to do this is via CoreAnimation rather than trying to do it yourself.
 

lancestraz

macrumors 6502a
Nov 27, 2005
898
0
RI
Use "applicationShouldTerminate" instead. That way you can return YES or NO depending on mainWindow's current alphaValue.

Code:
- (NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication *)sender {
	timer = [[NSTimer scheduledTimerWithTimeInterval:0.02 target:self selector:@selector(allWindowsFadeOUT:) userInfo:nil repeats:YES] retain];
	
	if ([mainWindow alphaValue] > 0.0)
		return NO;
	else
		return YES;
}


- (void)allWindowsFadeOUT:(NSTimer *)theTimer
{
	if ([mainWindow alphaValue] > 0.0) {
		[mainWindow setAlphaValue:[mainWindow alphaValue] - 0.1];
	}
	else
	{	
		[timer invalidate];
		[timer release];
		timer = nil;
		[NSApp terminate:nil];
	}
}
 

Darkroom

Guest
Original poster
Dec 15, 2006
2,445
0
Montréal, Canada
Yeah, the timer gets killed pretty much immediately after you create it.

Now first, my rant is that you probably shouldn't want to override the close behavior of the window. If someone is quitting your app, they want it gone. If your app lingers too long, then you get into a state where you could cancel restarts and shutdowns (bad).

That said, the easiest way to do this is via CoreAnimation rather than trying to do it yourself.

you're not the first to tell me that... and i won't disagree with you, it's probably bad... but the fadeout is really quick, and i think it adds a lot... i haven't studied core animation yet, but i'm looking forward to it in upcoming chapters of my dev book.

Use "applicationShouldTerminate" instead. That way you can return YES or NO depending on mainWindow's current alphaValue.

worked perfectly! thanks so much!
 

tskoti

macrumors newbie
Nov 5, 2008
6
0
how to handle Interruptions in Iphone

Hi All,
I am new to this Iphone Application Development, Plz help me with a sample code for how to handle the Interruptions (like incoming call, SMS alert, reminders) in Iphone,

It is very Urgent, any material for that also will be helpful,

Plz help me,

Thanks in advance,
Koti
 

gnasher729

Suspended
Nov 25, 2005
17,980
5,566
Hi All,
I am new to this Iphone Application Development, Plz help me with a sample code for how to handle the Interruptions (like incoming call, SMS alert, reminders) in Iphone,

It is very Urgent, any material for that also will be helpful,

Plz help me,

Thanks in advance,
Koti

developer.apple.com

Oh, sorry, for you it should be

dvlpr.ppl.cm
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.