Re: animating windows fade in/out
Re: animating windows fade in/out
- Subject: Re: animating windows fade in/out
- From: "I. Savant" <email@hidden>
- Date: Fri, 8 Dec 2006 01:13:11 -0500
Matt:
I'd venture a guess that this may be a bug. Though I don't have an
answer for you, there are two things I'd experiment with (that you
may have already):
1 - What happens when you forgo the animation *and* set alpha
directly to 0 and order out, then try the reverse?
2 - What happens when you add [indexWindow setAlphaValue: 1.0]; to
your - (void)animationDidEnd:(NSAnimation*)animation method so that
the alpha value is immediately set back to normal after the window is
ordered out?
I believe the answer to 1 would tell you whether the animation
itself really has anything to do with it while the answer to 2 would
(possibly) tell you whether something is happening between the time
you adjust the alpha and order the window out and the time you
reverse it.
Then again, it may get you exactly nowhere. :-D
--
I.S.
On Dec 8, 2006, at 12:24 AM, Matt Neuburg wrote:
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:
40gmail.com
This email sent to email@hidden
_______________________________________________
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