【发布时间】:2012-11-08 14:46:16
【问题描述】:
我有一个 .png 格式的轮子图像,我想知道如何制作动画以使其连续旋转,我在 stackoverflow 上搜索并找到了某些帮助我旋转图像的 sn-ps 代码,但它不会连续旋转,它会旋转几秒钟然后停止,代码如下
viewdidload中的代码
UIImageView *imageToMove =
[[UIImageView alloc] initWithImage:[UIImageimageNamed:@"horo_circle.png"]];
[self.view addSubview:imageToMove];
[self rotateImage:imageToMove duration:5.0
curve:UIViewAnimationCurveEaseIn degrees:180];
还有动画
- (void)rotateImage:(UIImageView *)image duration:(NSTimeInterval)duration
curve:(int)curve degrees:(CGFloat)degrees
{
// Setup the animation
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:duration];
[UIView setAnimationCurve:curve];
[UIView setAnimationBeginsFromCurrentState:YES];
// The transform matrix
CGAffineTransform transform =
CGAffineTransformMakeRotation(DEGREES_TO_RADIANS(degrees));
image.transform = transform;
// Commit the changes
[UIView commitAnimations];
}
以及导入后的以下几行
#define M_PI 3.14159265358979323846264338327950288 /* pi */
#define DEGREES_TO_RADIANS(angle) (angle / 180.0 * M_PI)
【问题讨论】:
-
还有其他问题正好问这个问题(连续旋转)My answer to the same question here
标签: objective-c ios uiimageview caanimation