Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

why CGAffineTransformRotate in autolayout will shift the animated view?

I want to rotate a imageView using the following code:

[UIView animateWithDuration:.25 animations:^{
    self.imageView.transform = CGAffineTransformRotate(self.plusView.transform, M_PI_4);
}];

the wired thing is that: if I run this code without auto layout, every thing is fine. but when using autolayout, the image view shift a litter pixel before rotate, why?

like image 297
user1687717 Avatar asked Oct 07 '22 01:10

user1687717


1 Answers

When using auto layout in Xcode 5, you need to add a constraint to fix the horizontal center and vertical center of the imageView in its container. If you are using storyboards, this can be easily done with the constraints options. You will also need to fix the width and height with constraints if you don't want the imageView auto-resized.

Pin the center of a view with constraints in Storyboard

Fix the size of a view with constraints in Storyboard

like image 97
chazzwozzer Avatar answered Oct 10 '22 03:10

chazzwozzer