Mark Nutter
Mark Nutter

Reputation: 5629

CGAffineTransformRotate shifts object before performing rotation

I am trying to animate a transform of a UIButton with CGAffineTransformRotate, and while it is performing the animation properly, it shifts the button about 15 pixels down and to the left before doing it. Here's the code performing the animated transformation:

[UIView animateWithDuration:0.5 delay:0.0 options:UIViewAnimationOptionTransitionNone
                 animations:^{
                     self.addCloseButton.transform = CGAffineTransformRotate(self.addCloseButton.transform, degreesToRadians(45));
                 }
                 completion:nil];

When I reverse the transformation it does the same thing except it shifts it back to its original position before animating (15 pixels up and 15 pixels to the right), and I do that with this code:

[UIView animateWithDuration:0.5 delay:0.0 options:UIViewAnimationOptionTransitionNone
                 animations:^{
                     self.addCloseButton.transform = CGAffineTransformIdentity;
                 }
                 completion:nil];

Why would this shift occur? The button was created using interface builder, and the shift happens immediately even if I set the animation duration higher or add a delay.

Upvotes: 1

Views: 845

Answers (2)

chazzwozzer
chazzwozzer

Reputation: 467

It is posible to fix this while still using auto layout and storyboards. See my answer on this question: https://stackoverflow.com/a/19582959

Upvotes: 0

Mark Nutter
Mark Nutter

Reputation: 5629

I figured it out: turns out having "Use Autolayout" selected on my xib (which adds a bunch of auto constraints) messes things up when trying to use transforms. Turning it off fixed my problem.

Upvotes: 1

Related Questions