0

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?

Dummy Code
  • 1,858
  • 4
  • 19
  • 38
  • [This](http://stackoverflow.com/questions/17116459/rotating-uiimageview-moves-the-image-off-screen#comment24766927_17116459) should solve your rotation issue. About jumping back to initial location: somehow your image's transform is getting reset. I am not sure how. Can you post your panning code too? – zambrey Jun 19 '13 at 01:29
  • @zambrey I looked around and saw it was an issue with autolayout issue. Do you have a solution for that? – Dummy Code Jun 19 '13 at 01:44
  • Sorry I don't presently know about that. But it feels weird that autolayout would cause such issue. In past I have implemented pinch and pan on UIImageView and I was not using autolayout then and it worked perfectly fine. Go ahead and try disabling autolayout and see if it works then. I hope above link resolved your rotation issue at least. – zambrey Jun 19 '13 at 02:05
  • @zambrey That's not the issue I was having. See http://stackoverflow.com/questions/12528019/gesture-recognizers-and-auto-layout-in-ios6-scaling-from-the-center and http://stackoverflow.com/questions/12943107/how-do-i-adjust-the-anchor-point-of-a-calayer-when-auto-layout-is-being-used/14105757#14105757 for more information. – Dummy Code Jun 19 '13 at 05:52

0 Answers0