Re: About nswindow animation?
Re: About nswindow animation?
- Subject: Re: About nswindow animation?
- From: Dominik Pich <email@hidden>
- Date: Sat, 10 Feb 2007 22:12:22 +0100
I'd not recommend that as it blocks the event queue.
Solution with NSViewAnimation:
- (void)orderOut:(id)sender {
if( !_fadingOut ) {
[self releaseAnimation];
[self fadeOutWindow];
}
}
-(void) releaseAnimation {
if( _animation != nil) {
if( [_animation isAnimating] )
{
[_animation stopAnimation];
}
[_animation release];
_animation = nil;
}
}
-(void)fadeOutWindow {
NSDictionary *animationParameters1 = [NSDictionary
dictionaryWithObjectsAndKeys:
self, NSViewAnimationTargetKey,
[NSValue valueWithRect: [self frame]],
NSViewAnimationEndFrameKey,
NSViewAnimationFadeOutEffect, NSViewAnimationEffectKey,
nil];
_animation = [[NSViewAnimation alloc] initWithViewAnimations:
[NSArray arrayWithObjects:animationParameters1, nil]];
[_animation setAnimationBlockingMode:NSAnimationNonblocking];
[_animation setDuration:1.0];
[_animation setFrameRate:30];
[_animation setDelegate:self];
_fadingOut = YES;
[_animation startAnimation];
}
- (void)animationDidEnd:(NSAnimation*)animation {
// set up the system to hide the menu bar
if(!_fadingOut) SetSystemUIMode(kUIModeAllHidden,
kUIOptionAutoShowMenuBar);
// put the menu bar back
else SetSystemUIMode(kUIModeNormal, 0);
[self setAcceptsMouseMovedEvents:!_fadingOut];
if(!_fadingOut) [self makeKeyWindow];
if(!_fadingOut) return;
_fadingOut = NO;
[super orderOut:self];
}
Am Feb 10, 2007 um 8:53 PM schrieb PGM:
I am concerned about the animation effect implemented using
nswindow.
For example, user click the red round button at the left up
corner, then I want to make my window fade out.
But using the NSViewAnimation Class, I can only capture the
NSWindow content view, that is,the content view in a window, no
the window self.
What you need to do is override your window's close method.
In your override of the close method, setup an NSViewAnimation
object with your window as the target (documented yes, but also
non-intuitive for a class called NSViewAnimation) and
NSViewAnimationFadeOutEffect as the effect.
When your animation has finished, call [super close] to actually
close your window.
You can also simply bypass NSViewAnimation and do in your NSWindow
subclass (typed in Mail, may need some tweaking):
- (void)close
{
float alpha;
while((alpha = [self alphaValue] ) > 0.0){
[self setAlphaValue:alpha - 0.2];
usleep((useconds_t)(1000000));
}
[super close];
}
Good luck, Patrick
_______________________________________________
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
_______________________________________________
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