我想创建一个图像的动画,使图像来回摆动,就像节拍器一样。动画的目标是模拟类似“旋转器”的效果。想象一下,只有上半部分,箭头会前后移动,直到它停在目标上。
到目前为止,我已经能够让箭头来回移动,但是动画的锚点是图像的中心。我希望那个锚点成为图像的底部中心。为了模拟节拍器,锚点不能在当前位置。我该如何进行此更改?动画代码如下:
#define RADIANS(degrees) ((degrees * M_PI) / 180.0)
CGAffineTransform leftWobble = CGAffineTransformRotate(CGAffineTransformIdentity, RADIANS(90));
CGAffineTransform rightWobble = CGAffineTransformRotate(CGAffineTransformIdentity, RADIANS(-90));
arrow.transform = leftWobble; // starting point
[UIView beginAnimations:@"wobble" context:(__bridge void *)arrow];
[UIView setAnimationRepeatAutoreverses:YES]; // important
[UIView setAnimationRepeatCount:10];
[UIView setAnimationDuration:.5];
[UIView setAnimationDelegate:self];
[UIView setAnimationDidStopSelector:@selector(wobbleEnded:finished:context:)];
arrow.transform = rightWobble; // end here & auto-reverse
[UIView commitAnimations];