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.
The
+[UIView beginAnimations:context:]method allows you to pass along a specificcontextthat 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
animationDidStopmethod, just invoke the method defined by the protocol. So even though you have one single class-wideanimationDidStopmethod it can act as a fan-out method dispatcher.