Monday, 4 July 2011

Speedo Meter Test Project

I got this speedo meter test project working. It's quite interesting seeing the needle slowly moves to different positions when you clicked on any of the 4 buttons.

Move #1 - 0 degree
Move #2 - 90 degrees
Move #3 - 180 degrees
Move #4 - 270 degrees

But would certainly need a lot more work to make it moves/trembles/shakes like a speedo meter in the car when you step on the accelerator....

The needle image is from

The loadView method of the view controller only did the following plus the button creation work:

    myImageRect = CGRectMake(0.0f, 200.0f, 320.0f, 109.0f);
    myImage = [[UIImageView alloc] initWithFrame:myImageRect];
    [myImage setImage:[UIImage imageNamed:@"VM1_D.png"]];
    myImage.opaque = YES
    [self.view addSubview:myImage];
    [myImage release];

Then when clicked, each of the button's action simple do the following, with different parameter used. #1 is "M_PI*0.0", #2 is "M_PI*0.5", #3 is "M_PI*1.0" and #4 is "M_PI*1.5".

    [UIView beginAnimations:nil context:NULL];
    [UIView setAnimationDuration:1.5];
    myImage.transform = CGAffineTransformMakeRotation(M_PI*0.0);
    [UIView commitAnimations];

Source Code for Speedo Meter Project (Updated)


  1. thnx a lot.....

  2. Hi!,
    this project work but, you never use OO programing??

    1. Why does every Project has to be OO?
      You can create a needle object, then pass the value as parameter.