animating windows fade in/out
animating windows fade in/out
- Subject: animating windows fade in/out
- From: Matt Neuburg <email@hidden>
- Date: Thu, 07 Dec 2006 21:24:15 -0800
- Thread-topic: animating windows fade in/out
I'm having an odd problem; maybe someone will spot the solution. I have two
windows, call them w1 and w2. W1 is on the screen; I want to fade it out
while fading in w2. I'm doing that using NSViewAnimation. It works great.
The problem is that later I want to close w2 and show w1 again. W1 doesn't
appear! I'm setting its alpha value back to 1 (because it became 0 as a
result of the fade), I'm telling it to makeKeyAndOrderFront, its frame is
right, it even appears in the Window menu, but I don't actually *see* it! Is
this some sort of buffering foo?
If I don't use the NSViewAnimation in the first place - that is, if I get
rid of w1 by just ordering it out and opening w2 with no animation - then
swapping back to w1 works fine. The problem happens only if I animate.
Here's the animation code. The actual names of the windows are "indexWindow"
and "window" (sorry about that).
- (void) finishOpeningStack: (id) dummy {
// if I uncomment these lines, it all works fine (without animation)
//[window makeKeyAndOrderFront:self];
//[indexWindow orderOut:self];
//return;
NSMutableDictionary* d1 = [NSMutableDictionary
dictionaryWithCapacity:4];
NSMutableDictionary* d2 = [NSMutableDictionary
dictionaryWithCapacity:4];
[d1 setObject: indexWindow forKey: NSViewAnimationTargetKey];
[d2 setObject: window forKey: NSViewAnimationTargetKey];
[d1 setObject: NSViewAnimationFadeOutEffect forKey:
NSViewAnimationEffectKey];
[d2 setObject: NSViewAnimationFadeInEffect forKey:
NSViewAnimationEffectKey];
[d1 setObject: [NSValue valueWithRect: [indexWindow frame]] forKey:
NSViewAnimationStartFrameKey];
[d1 setObject: [NSValue valueWithRect: [indexWindow frame]] forKey:
NSViewAnimationEndFrameKey];
[d2 setObject: [NSValue valueWithRect: [window frame]] forKey:
NSViewAnimationStartFrameKey];
[d2 setObject: [NSValue valueWithRect: [window frame]] forKey:
NSViewAnimationEndFrameKey];
NSViewAnimation* anim = [[NSViewAnimation alloc] initWithViewAnimations:
[NSArray arrayWithObjects: d1, d2, nil]];
[anim setDelegate: self];
[anim setDuration: 0.8];
[anim setAnimationCurve: NSAnimationEaseInOut];
[anim setProgressMarks: [NSArray arrayWithObject: [NSNumber
numberWithFloat: 0.4]]];
[anim startAnimation];
[anim release];
}
- (BOOL)animationShouldStart:(NSAnimation*)animation {
NSLog(@"%@", NSStringFromRect([ indexWindow frame ]));
[window setAlphaValue: 0.0];
[window orderWindow: NSWindowBelow relativeTo: [indexWindow
windowNumber] ];
return YES;
}
- (void)animation:(NSAnimation*)animation
didReachProgressMark:(NSAnimationProgress)progress {
if (fabs(progress - 0.4) < 0.001) { // ah, floating point comparison,
ain't life grand
[window makeKeyAndOrderFront: self];
}
}
- (void)animationDidEnd:(NSAnimation*)animation {
[indexWindow orderOut:self];
}
And here is how I later attempt to bring the first window back again:
- (void) openIndex {
[indexWindow setAlphaValue: 1.0];
[indexWindow makeKeyAndOrderFront:self];
[window orderOut: self];
}
Thx - m.
--
matt neuburg, phd = email@hidden, http://www.tidbits.com/matt/
pantes anthropoi tou eidenai oregontai phusei
AppleScript: the Definitive Guide - Second Edition!
http://www.amazon.com/gp/product/0596102119
Take Control of Word 2004, Tiger, and more -
http://www.takecontrolbooks.com/tiger-customizing.html
Subscribe to TidBITS! It's free and smart. http://www.tidbits.com/
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden