我想按照角度在iOS中旋转图像

Nis*_*shi 2 animation angle uiimageview ios

http://screencast.com/t/OAb6BDNgiK

在上面的图像中有一条白线,我想只在每个角度为圆圈中的这个图像设置动画.假设我的角度是20度,那么白线在58度内动画,它将像下面的图像一样

http://screencast.com/t/xuzngv8gRY

她是我的代码

 UIImageView *imgBenchmark = [[UIImageView alloc]initWithFrame:CGRectMake(153,70, 1, 26)];
self.benchmark = imgBenchmark;
[imgBenchmark release];

self.benchmark.layer.anchorPoint = CGPointMake(self.benchmark.layer.anchorPoint.x, self.benchmark.layer.anchorPoint.y*2);
self.benchmark.backgroundColor = [UIColor clearColor];
self.benchmark.image = [UIImage imageNamed:@"line.png"];
[self.view addSubview:self.benchmark];

[self rotateIt1:20];

    -(void) rotateIt1:(float)angl
{

[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.01f];

[self.benchmark setTransform: CGAffineTransformMakeRotation((M_PI / 9) *angl)];

[UIView commitAnimations];
}
Run Code Online (Sandbox Code Playgroud)

Viv*_*ier 5

背景图片(名为@"背景"):

在此输入图像描述

白线(名​​为@"white-line"):

在此输入图像描述

试试这段代码:

ViewController.h

#import <UIKit/UIKit.h>

@interface ViewController : UIViewController

@property (nonatomic, strong) UIImageView *whiteLine;

@end
Run Code Online (Sandbox Code Playgroud)

ViewController.m

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.2

    UIImageView *background = [[UIImageView alloc]initWithFrame:CGRectMake(55, 20, 209, 105)];
    background.image = [UIImage imageNamed:@"Background"];
    [self.view addSubview:background];

    self.whiteLine = [[UIImageView alloc]initWithFrame:CGRectMake(156, 20, 7, 210)];
    self.whiteLine.image = [UIImage imageNamed:@"white-line"];
    [self.view addSubview:_whiteLine];

    [self rotateIt1:20];

}

-(void) rotateIt1:(float)angl
{

    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationDuration:5];
    self.whiteLine.transform = CGAffineTransformMakeRotation((M_PI / 180) * angl);
    [UIView commitAnimations];
}
Run Code Online (Sandbox Code Playgroud)

这对我有用.

源代码:http://speedy.sh/wUZQm/Speedometer.zip

或者有一个自定义插件:https: //github.com/sabymike/MSSimpleGauge