IOS iPhone: Why is my image rotation distorting the image?

I searched all over the internet to find out how to rotate an image in a UIImageView without distorting the image. None of the examples I've tested worked. So I have to ask a specific question here.

My code for rotation is shown below. And the result is presented in the images I linked to (with a reputation up to 5, I could not attach images in the post). I entered the angle values ​​in and the image shows how the image ended after rotation.

Rotation works great with 0, 90, 180 and 270 degrees. Everything else distorts the image.

self rotateImage:_compassScale duration:1 curve:UIViewAnimationCurveEaseIn degrees:(CGFloat)bearing];

      

...

- (void)rotateImage:(UIImageView *)image duration:(NSTimeInterval)duration curve:(int)curve degrees:(CGFloat)degrees
{
    [UIView beginAnimations:nil context:NULL];
    [UIView setAnimationDuration:duration];
    [UIView setAnimationCurve:curve];
    [UIView setAnimationBeginsFromCurrentState:YES];

    CGAffineTransform transform = CGAffineTransformMakeRotation(DEGREES_TO_RADIANS(-degrees));
    image.transform = transform;


    [UIView commitAnimations];
}

      

90 degrees 120 degrees and skewed

There are 3 images if you change the url to Im1, Im4 and Im5. Rep did not allow more than two links.

After a lot of work, I found that the limitations are due to skew. The NESW ring (compass rose?) Is an image in which I am focusing on another image that is the frame of the compass. And the togheter with these images is a textbox that also focuses on images.

If I drag the NESW ring to a different location on the screen, the image will not be distorted. But instead, it moves around the screen.

I moved all 3 items and then brought them back to their original coordinates on the screen. There are no more distortions. But when I change the angle in the Text box, both images change position slightly, and the change doesn't seem like the change in the position I for the ring is related to the position of the chande for the frame. The peculiarity is that I don't have any code that moves the compass frame!

Any ideas how to counter this?

+3


source to share


1 answer


Disable auto shutdown. Select the xib or storyboard and in the File Inspector (the first of the right-hand panels) the "Use autolayout" checkbox is checked. Uncheck the box (it is enabled by default).

Then you should get the expected results.



You should always disable autoplay unless you have a reason to use it.

+1


source







All Articles