Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

wasteman

macrumors newbie
Original poster
Nov 1, 2010
1
0
Hi I have searched the internet with this and haven't found this problem anywhere else.

I am using the UIRotationGestureRecognizer to rotate an object on the screen.

When I do the rotation action with two fingers the imageView rotates perfectly. However if I then take my fingers off and do the rotate action again it jumps back to its original place and rotates from there. I want it to remember where it is and rotate from its last spot.

My code reads like this;
Code:
- (void)viewDidLoad {
    [super viewDidLoad];
		
		UIGestureRecognizer *recognizer;
		
		//rotation
		recognizer = [[ UIRotationGestureRecognizer alloc] initWithTarget:self action:@selector(handleRotation:)];
		rotationGR = (UIRotationGestureRecognizer *)recognizer;
		[self.view addGestureRecognizer:rotationGR];
		[recognizer release];
}

-(void) handleRotation:(UIRotationGestureRecognizer *)recognizer {
		
				float rotationInDegrees = recognizer.rotation * (180/M_PI);
				NSLog(@"%f", rotationInDegrees);
				planet1.transform = CGAffineTransformMakeRotation(recognizer.rotation);
		}

The rotationInDegrees is in there because when I rotate the ImageView a certain amount of degrees I want to trigger something. However rotationInDegrees resets on each rotation. I have tried using another int like

newInt = newInt + rotationInDegrees;

but because rotationInDegrees constantly updates it is actually adding many numbers instead of just the latest rotationInDegrees number. If anyone could help me solve this too that would be great.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.