2

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];
}
4

5 回答 5

5

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

在此处输入图像描述

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

在此处输入图像描述

试试这个代码:

视图控制器.h

#import <UIKit/UIKit.h>

@interface ViewController : UIViewController

@property (nonatomic, strong) UIImageView *whiteLine;

@end

视图控制器.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];
}

这对我有用。

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

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

于 2013-07-03T15:36:11.247 回答
1

尝试这个

 [UIView animateWithDuration:0.50 animations:^{
            CGFloat angle = 1.5707f; // set angle as per your requirement
            tapview.transform = CGAffineTransformRotate(tapview.transform, angle);

        }];
于 2013-07-03T11:23:49.047 回答
1

尝试这个:

-(void) rotateImage:(float)angleRadians{

    self.transform = CGAffineTransformMakeRotation(angleRadians);
    CATransform3D rotatedTransform = imgMain.layer.transform;
    imgMain.layer.transform = rotatedTransform;    
}

还看到这个:

  1. iphone:如何使用触摸事件旋转矩形图像?
  2. 将 UIImage 或 UIView 旋转到特定角度,而不是角度量
于 2013-07-03T09:57:43.437 回答
0

试试这个:拍一张 alpha 为 0 的图像,除了那条白线,然后将该图像放在彩色仪表上 [必须开发一个适合仪表的适当图像。],现在使用 whiteGaugeIndicator,您可以将其移动时钟明智地使用以下 LOC:

whiteGaugeIndicator.transform = CGAffineTransformMakeRotation(M_PI/9);
于 2013-07-03T10:06:14.983 回答
0

尝试以下链接

如何以某个角度旋转图像

iphone-sample-rotating-uiimage

于 2013-07-03T10:54:34.887 回答