Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Modify view animation while running



Hi.

Does anybody know if it is possible to change the target frame of an NSViewAnimation while it is running?

What I'm trying to do is to "fly" a view to the point where the user clicks, but if in the middle of the animation, the user clicks somewhere else, the animation should start moving towards the new point. With my current approach, when the view is moving and I click somewhere else, the view "jumps" to the final location of the current animation and starts the new one from there.

I've tried to stop the progress of an NSViewAnimation before it ends, but, as the documentation says, "Invoking the NSAnimation method stopAnimation on a running NSViewAnimation object moves the animation to the end frame." If I could just stop the animation right where it is now, I could achieve what I want.

Here is the code I have now. The flyToFrame method is called on every click:

- (id)initWithFrame:(NSRect)frame
{
	...
		itemAnimation = [[NSViewAnimation alloc] initWithViewAnimations:nil];
		[itemAnimation setDuration:2];
		[itemAnimation setFrameRate:30.0];
		[itemAnimation setAnimationCurve:NSAnimationEaseInOut];
		[itemAnimation setDelegate:self];
	...
}

- (void)flyToFrame:(NSRect)targetRect
{
// stop the animation
[itemAnimation stopAnimation];
[itemAnimation setCurrentProgress:0];

// create the dictionary of animation parameters
NSMutableDictionary *itemAnimDict = [NSMutableDictionary dictionaryWithCapacity:2];
[itemAnimDict setObject:self forKey:NSViewAnimationTargetKey];
[itemAnimDict setObject:[NSValue valueWithRect:[self frame]] forKey:NSViewAnimationStartFrameKey];
[itemAnimDict setObject:[NSValue valueWithRect:targetRect] forKey:NSViewAnimationEndFrameKey];


// set the array of animations and start the animation
[itemAnimation setViewAnimations:[NSArray arrayWithObjects:itemAnimDict, nil]];
[itemAnimation startAnimation];
}


Thanks,
Daniel
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/email@hidden

This email sent to email@hidden


Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.