Reputation: 40339
I'm concerned that this is impossible, because +setAnimationDelegate: of UIView is a class method. But maybe I am wrong with that?
Background: The problem is, that I have many objects of the same class, and I want to implement a method which does some nice animations specially for that object. Those animations are a little complex and consist of a few phases. So I need to be notified when an animation stopped. Now, it may happen that 10 objects from that class start animating at same time.
Upvotes: 1
Views: 309
Reputation: 13433
The +[UIView beginAnimations:context:]
method allows you to pass along a specific context
that is passed along to the completion method. You can use that context to disambugate between the various instances when the completion method is called.
Since the context is typed as a (void *)
it can be pretty much anything you want it to be, i.e. pointer to an object instance, a unique ID, or a custom struct.
If your objects all implement a common protocol you can pass them along as the context and in the animationDidStop
method, just invoke the method defined by the protocol. So even though you have one single class-wide animationDidStop
method it can act as a fan-out method dispatcher.
Upvotes: 1
Reputation: 185731
Each animation block has its own delegate. +[UIView setAnimationDelegate:]
and +[UIView setAnimationDidStopSelector:]
only do anything when called in between +[UIView beginAnimations:context:]
and +[UIView commitAnimations]
, and only affect the animation set up by that block.
Upvotes: 2
Reputation: 60140
The only way to set different animation delegates for multiple objects is to have them be of separate subclasses of UIView. As you thought, since +setAnimationDelegate:
is a class method, you can't set separate animation delegates for different instances of the same class.
Upvotes: 1