Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS iPhone: Why does my image rotation skew the image?

I have searched all over Internet to find out how to rotate an image in UIImageView without the image going skewed. None of the examples I have tested has worked. So I have to post a specific question here.

My code for the rotation is shown here below. And the result is presented in the images that I linked to (With a rep under 5 I could not attach the images in the post). I entered the angle values in and the image show how the image ended up after the rotation.

The rotation works fine with 0, 90, 180 and 270 degrees. Everything else skews 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 more images if you change the the URL to Im1, Im4 and Im5. Rep did not allow to post more then 2 links.

After a lot of work I have found out that the Constraints has to do with the skewing. The NESW-ring (compass rose?) is an image that i centered in another image that is the compass frame. And togheter with these images is the Text field that is also centered with the images.

If I drag the NESW-ring away to another place on the screen, the image does not skew. But it moves around on the screen instead.

I moved all 3 of the items and then draged them back to the original coordinates on the screen. There are no longer any skewing. But when I change the angle in the Text field both Images changes position a bit and the change does not seem that the change i position for the ring is connected to position chande for the frame. The peculiar is that I have no code that moves the compass fram!

Any ideas how to counter this?

like image 991
user2078203 Avatar asked Jan 18 '26 17:01

user2078203


1 Answers

Turn off autolayout. Select the xib or storyboard, and in the File Inspector (first of the right-hand panes) there is a "use autolayout" checkbox. Uncheck it (it is on by default).

Then you should get expected results.

You should always keep autolayout OFF unless you have a reason to use it.

like image 57
foundry Avatar answered Jan 20 '26 09:01

foundry



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!