• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag
 

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Modify view animation while running
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Modify view animation while running


  • Subject: Modify view animation while running
  • From: Daniel Gobera <email@hidden>
  • Date: Sat, 11 Nov 2006 12:04:55 -0800

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:
This email sent to email@hidden


  • Follow-Ups:
    • Re: Modify view animation while running
      • From: Bill Cheeseman <email@hidden>
  • Prev by Date: Re: NSScrollView bug or misunderstood behavior?
  • Next by Date: Re: Cocoa - To display a string in 2 different lines but in the same table column and row in different fonts - Using the concept of cocoa bindings.
  • Previous by thread: Re: NSScrollView bug or misunderstood behavior?
  • Next by thread: Re: Modify view animation while running
  • Index(es):
    • Date
    • Thread