CABasicAnimation *positionAnim=[CABasicAnimation animationWithKeyPath:@"position"];
[positionAnim setFromValue:[NSValue valueWithCGPoint:CGPointMake(img.center.x, img.center.y)]];
[positionAnim setToValue:[NSValue valueWithCGPoint:CGPointMake(img.center.x+INSETS+PIC_WIDTH, img.center.y)]];
[positionAnim setDelegate:self];
[positionAnim setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]];
[positionAnim setDuration:0.25f];
[img.layer addAnimation:positionAnim forKey:nil];
[img setCenter:CGPointMake(img.center.x+INSETS+PIC_WIDTH, img.center.y)];
只有这两个代理方法 顾名思义,一个开始一个结束,CAAnimation实现代理方法不同于其他,CAAnimation不用声明CAAnimationDelegate。直接重写方法即可
/* Delegate methods for CAAnimation. */
@interface NSObject (CAAnimationDelegate)
/* Called when the animation begins its active duration. */
- (void)animationDidStart:(CAAnimation *)anim;
/* Called when the animation either completes its active duration or
* is removed from the object it is attached to (i.e. the layer). 'flag'
* is true if the animation reached the end of its active duration
* without being removed. */
- (void)animationDidStop:(CAAnimation *)anim finished:(BOOL)flag;
@end