I am using the accelerometer to move an image (helicopter) around the screen. I'm trying to add code so when the helicopter moves forward it rotates the uiimageview by 20 degrees, when the helicopter moves backwards it rotates the uiimageview by -20 degrees, the idea being to create the effect that the helicopter moves more realistically. However, when the rotation is applied the uiimageview moves back to its original starting position (the position I have placed it in the story bard). Any ideas why? Here's the code:
-(void)outputAccelerationData:(CMAcceleration)acceleration
{
if (helicoptervalueX>1.5){
helicopterrotation = 1;
helicopter.transform = CGAffineTransformRotate(CGAffineTransformIdentity,0.34906585 );
NSLog(@"Tilt forward");
} else if (helicoptervalueX < -1.5){
helicopterrotation = -1;
helicopter.transform = CGAffineTransformRotate(CGAffineTransformIdentity, -0.34906585);
NSLog(@"Tilt backward");}
else if (helicoptervalueX<=1.5 && helicoptervalueX>=-1.5){
helicopterrotation = 0;
helicopter.transform = CGAffineTransformRotate(CGAffineTransformIdentity, 0);
NSLog(@"Helicopter flat");}
helicoptervalueX = -(acceleration.y*50.0)+calibrationx;
helicoptervalueY = (acceleration.x*50.0)+calibrationy;
int helicopternewX = (int)(helicopter.center.x + helicoptervalueX);
if (helicopternewX > 518) {
helicopternewX = 518;}
if (helicopternewX < 50){
helicopternewX = 50;}
int helicopternewY = (int)(helicopter.center.y - helicoptervalueY);
if (helicopternewY > 295){
helicopternewY = 295;}
if (helicopternewY < 25){
helicopternewY = 25;}
CGPoint helicopternewCenter = CGPointMake(helicopternewX, helicopternewY);
helicopter.center = helicopternewCenter;
}