The post by Matthijs Hollemans has a very good explanation for auto-layout and rotation. You can find it here: http://www.raywenderlich.com/20881/beginning-auto-layout-part-1-of-2
Usually you need about 4 limits to correctly position your view. If my looks are of constant size, I prefer to embroider height and width. After that, you can use the restrictions of the leading and upper spaces to do whatever you want. For example, you can set IBOutlets for leading and upper space limits for your views:
@interface ViewController : UIViewController { IBOutlet NSLayoutConstraint *_leadingSpaceConstraint; IBOutlet NSLayoutConstraint *_topSpaceConstraint; }
Then drag control from the outlet to your restriction. Now you can directly change the view restriction from the code:
_leadingSpaceConstraint.constant = NEW_CONSTRAINT_VALUE;
To commit changes you need to call:
[self.view layoutIfNeeded]
And if you want to make it animated:
[UIView animateWithDuration:0.25 animations:^{ [self.view layoutIfNeeded]
I think it will work in willAnimateRotationToInterfaceOrientation, because you do not need to break any restrictions with this approach.
Example: You have two square images in portrait orientation, one below the other. For example, set the “leading surveillance space” limits to 20. Then set the “upper space to limit the supervisor” to 20 for the first view and 120 for the second. This will be our default setting.
Then, after the turn, you need to recount your limitations. Now set both upper limits to 20 and the leading limits to 20 and 120 respectively. Then commit the changes using layoutIfNeeded.
Hope this helps.
Flar Apr 25 '13 at 7:21 2013-04-25 07:21
source share