The delegate is my view controller.
I am setting the delegate via:
CABasicAnimation theAnimation;
theAnimation.delegate = self;
Then I configure the animation and add the animation to the layer, and I verified it is animating correctly on the device.
However, I cannot get this delegate method to be called:
-(void)animationDidStop:(CAAnimation *)anim finished:(BOOL)flag {
NSLog(@"animationDidStop called.");
}
Any ideas?
Also, I could not find anywhere the protocol my view controller adopts for the CAAnimation delegate methods. I thought all delegate objects had to adopt a protocol?
Thank you!
Delegation and formal protocols are orthogonal concepts:
Formal protocols are a pretty recent addition to the Objective-C programming language — as a matter of fact, they were introduced after CoreAnimation (née LayerKit).
The way of doing things prior to the introduction of
@protocol— and the wayQuartzCorestill works — was declaring a category onNSObjectas a so called “Informal Protocol”. It is only recently that Apple started formalizing these — seeNSURLConnectionfor such an example, which gained it’s delegate protocols with the current releases of iOS/OS X.After this brief aside on history, now to your problem:
If what you are showing is a verbatim copy of your code, then that cannot work. In fact, if you aren’t using ARC you are pretty lucky that the above code doesn’t crash due to a
EXC_BAD_ACCESS. You should totally set the value ofanimationto something meaningful before trying to send messages to it…