I created 2 NSAnimation objects of flipping the view with another view. I'd like to run 2 these animations simultaneously. I cannot use NSViewAnimation, since it's now about animating any of view properties.
Here is the animation creation:
self.animation = [[[TransitionAnimation alloc] initWithDuration:1.0 animationCurve:NSAnimationEaseInOut] autorelease];
[self.animation setDelegate:delegate];
[self.animation setCurrentProgress:0.0];
[self.animation startAnimation];
I tried to link 2 animations, but probably it didn't work for some reason. I took an example from: Apple developer site
configuring the NSAnimation object to use NSAnimationNonblocking doesn't show any animation at all...
EDIT: The second animation is exactly the same as the first one and created in the same place the first is created.
TransitionAnimation is a subclass of NSAnimation, where the setCurrentProgress looks like that:
- (void)setCurrentProgress:(NSAnimationProgress)progress {
[super setCurrentProgress:progress];
[(NSView *)[self delegate] display];
}
the delegate is NSView in this case, which in its drawRect function applies a time-dependent CIFilter on a CIImage. The problem is that it runs synchronous and the second animation starts right after end of the first. Is there a way to run them simultaneously?
NSAnimationis not really the best choice for animating multiple objects and their properties simultaneously.Instead, you should make your views conform to the
NSAnimatablePropertyContainerprotocol.You can then set up multiple custom properties as animatable (in addition to the properties already supported by
NSView), and then you can simply use your views'animatorproxy to animate the properties:Apart from making animation very simple, it also allows you to animate multiple objects simultaneously using an
NSAnimationContext:You can also set the duration and supply a completion handler block:
The
NSAnimationandNSViewAnimationclasses are much older than the animator proxy support and I highly recommend that you move away from them if possible. Supporting theNSAnimatablePropertyContainerprotocol is much simpler than managing all theNSAnimationdelegate stuff. The Lion support for custom timing functions and completion handlers means there's really no need to do that any more.For a standard
NSViewobject, if you want to add animation support to a property in your view, you just need to override the+defaultAnimationForKey:method in your view and return an animation for the property:I've created a simple sample project that shows how to animate multiple properties of a view simultaneously using the
NSAnimatablePropertyContainerprotocol.All your view needs to do to update successfully is make sure that
setNeedsDisplay:YESis called when any of the animatable properties are modified. You can then get the values of those properties in yourdrawRect:method and update the animation based on those values.If you want a simple progress value that is analogous to the way things work with
NSAnimation, you could define aprogressproperty on your view and then do something like this:You can then access
self.progressin yourdrawRect:method to find out the current value of the animation.