2

http://screencast.com/t/OAb6BDNgiK

In above image there is one white line, I want to animate this image in the circle only as per angle. Suppose if my angle is 20 degree then that white line animate in 58 degree, and it will come like following image

http://screencast.com/t/xuzngv8gRY

Her is my code

 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];
}
Nishi
  • 683
  • 1
  • 12
  • 31
  • I tried for the same...image is rotating but not with proper angle and proper frame.I want my white line image as per circle. My original image is on 0 degree and if my angle is 58 degree then it will move like this – Nishi Jul 03 '13 at 11:01
  • u r trying to rotate that white line ryt?wat is that ?is that a rectangle image? and sorry for the first post because when i search i gt lots of option for rotation and i thought you didnt try anythng yet – Navi Jul 03 '13 at 11:04
  • yes.. its UIImageView same as showing in first image..and now as per angle I need to rotate that image... – Nishi Jul 03 '13 at 11:07

5 Answers5

5

Background image ( named @"Background" ) :

enter image description here

The white line ( named @"white-line" ) :

enter image description here

An try this code :

ViewController.h

#import <UIKit/UIKit.h>

@interface ViewController : UIViewController

@property (nonatomic, strong) UIImageView *whiteLine;

@end

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

It's work for me.

Source code : http://speedy.sh/wUZQm/Speedometer.zip

Or there are a custom plugin : https://github.com/sabymike/MSSimpleGauge

VivienCormier
  • 1,133
  • 1
  • 11
  • 16
  • but it y - axis is not changing as per angle only the line rotates like speedometer needle...If possible can you please create demo for the same thansk – Nishi Jul 05 '13 at 07:59
1

try this:

-(void) rotateImage:(float)angleRadians{

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

also see this:

  1. iphone : How to rotate a rectangle image with touch events?
  2. Rotate a UIImage or UIView to a particular angle, NOT an amount of angle
Community
  • 1
  • 1
DharaParekh
  • 1,730
  • 1
  • 10
  • 17
  • I tried this,white line is animating but not as in circular format.....image is rotating but not with proper angle and proper frame.I want my white line image as per circle. My original image is on 0 degree and if my angle is 58 degree then it will move like first image – Nishi Jul 03 '13 at 11:12
1

Try this

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

        }];
Raj
  • 637
  • 13
  • 32
0

Try this: Take an image with alpha being 0, except for that white line and place that image on the coloured gauge [An appropriate image so as to fit the gauge will have to be developed.], now taking whiteGaugeIndicator you can move it clock wise using the below LOC:

whiteGaugeIndicator.transform = CGAffineTransformMakeRotation(M_PI/9);
Say2Manuj
  • 709
  • 10
  • 20
0

Try following links

how-to-rotate-an-image by-some-angle

iphone-sample-rotating-uiimage

Community
  • 1
  • 1
Navi
  • 1,696
  • 2
  • 17
  • 36