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?
NSAnimation
is not really the best choice for animating multiple objects and their properties simultaneously.Instead, you should make your views conform to the
NSAnimatablePropertyContainer
protocol.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'animator
proxy 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
NSAnimation
andNSViewAnimation
classes are much older than the animator proxy support and I highly recommend that you move away from them if possible. Supporting theNSAnimatablePropertyContainer
protocol is much simpler than managing all theNSAnimation
delegate 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
NSView
object, 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
NSAnimatablePropertyContainer
protocol.All your view needs to do to update successfully is make sure that
setNeedsDisplay:YES
is 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 aprogress
property on your view and then do something like this:You can then access
self.progress
in yourdrawRect:
method to find out the current value of the animation.