Is it possible to have more than one animation delegate at the same time?

I am concerned that this is not possible because setAnimationDelegate: from UIView is a class method. But maybe I'm wrong?

Background: The problem is that I have many objects of the same class, and I want to implement a method that does some nice animations specifically for that object. These animations are a bit complex and have several steps. So I need to be notified when the animation has stopped. Now it can happen that 10 objects from this class start animating at the same time.

+1


a source to share


3 answers


The method +[UIView beginAnimations:context:]

allows you to pass a specific context

one that is passed along with the finalizer. You can use this context to blur between different instances when you call the finalizer.

Since the context is typed like (void *)

, it can be pretty much anything you want, like a pointer to an object instance, a unique identifier, or a custom structure.



If your objects implement a common protocol, you can pass them as context and in a method animationDidStop

, just call the method defined by the protocol. Therefore, even though you have one method of a class animationDidStop

class, it can act as a dispatcher for the fork methods.

+1


a source


Each animation block has its own delegate. +[UIView setAnimationDelegate:]

and +[UIView setAnimationDidStopSelector:]

are executed only when called between +[UIView beginAnimations:context:]

and +[UIView commitAnimations]

and affect only the animation set by this block.



+2


a source


The only way to set different animation delegates for multiple objects is to have them separate UIView subclasses. As you thought, since +setAnimationDelegate:

is a class method, you cannot set separate animation delegates for different instances of the same class.

+1


a source







All Articles