小编Bor*_*ath的帖子

如何连续旋转图像

我有一个.png格式的轮子图像,我想知道我怎么能动画,以便它连续旋转,我搜索stackoverflow并找到某些代码片段,帮助我旋转我的图像,但它不会连续旋转,它会只需旋转几秒钟即可停止,代码如下

viewdidload中的代码

UIImageView *imageToMove =
[[UIImageView alloc] initWithImage:[UIImageimageNamed:@"horo_circle.png"]];
[self.view addSubview:imageToMove];

[self rotateImage:imageToMove duration:5.0 
            curve:UIViewAnimationCurveEaseIn degrees:180];
Run Code Online (Sandbox Code Playgroud)

和动画

- (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];
}
Run Code Online (Sandbox Code Playgroud)

以及导入后的以下行

#define M_PI   3.14159265358979323846264338327950288   /* pi */

#define DEGREES_TO_RADIANS(angle) (angle / 180.0 * M_PI)
Run Code Online (Sandbox Code Playgroud)

objective-c uiimageview caanimation ios

6
推荐指数
1
解决办法
2万
查看次数

标签 统计

caanimation ×1

ios ×1

objective-c ×1

uiimageview ×1