I am currently designing a little game as a learning project and it is basically the following, a image is rotated and scaled on viewDidLoad and another image is a direct copy of the original image.
So basically there is a image that is a little bit different from the other, the objective is to scale it back down, rotate it and move it on top of the other image with 5 pixels, 5 degrees of rotate and 5 percent scale.
My problem is that when I run my rotate and scale methods the image just jumps back to it's starting position.
My two methods are below.
Rotate
//rotation gesture recognizer response
- (void)respondToRotateGesture:(UIRotationGestureRecognizer *)gesture {
if (gesture.state == UIGestureRecognizerStateBegan || gesture.state == UIGestureRecognizerStateChanged) {
image.transform = CGAffineTransformRotate(gesture.view.transform, gesture.rotation);
}
gesture.rotation = 0;
}
Scale
//pinch gesture recognizer
- (void)respondToPinchGesture:(UIPinchGestureRecognizer *)gesture {
if (gesture.state == UIGestureRecognizerStateBegan || gesture.state == UIGestureRecognizerStateChanged) {
image.transform = CGAffineTransformScale(image.transform, gesture.scale, gesture.scale);
}
gesture.scale = 1;
}
I am trying to understand why when I try and rotate and scale, it doesn't rotate around the center of the image or scale from the center of the image. It rotates from the upper left hand corner and scales all weird. And when I pinch the image to zoom out it jumps back to it's starting position in the left hand corner of the screen.
I have a pan gesture to move the image around and that is working fine, however these two are causing me issues and are not smooth.
Does anyone know how to make these work smoother or and suggestions?