2

I'm trying to figure out auto layout constraints with a view in portrait and landscape. In portrait I have a container view (but any view will do) that is 320x200 pixels. When the phone is rotated to landscape, I would like that container view to fill the screen at 480x320.

Right now I'm doing this entirely in IB, and am trying to keep it that way for now. I struggle with the dang blue and purple constraint icons appearing when I try to set the the view to resize as I would like it to.

I've watched the WWDC auto-layout videos and have auto-layout working in other views, but I just can't get this seeming simple change to occur.

Any help would be appreciated. Thank you.

4

2 回答 2

2

In the 2012 WWDC video 228 - Mastering Auto layout, he showed something like this

for (UIView *aView in [yourViewController subviews]) {
if ([aView hasAmbiguousLayout]) {
    NSLog(@"View Frame %@", NSStringFromCGRect(aView.frame));
    NSLog(@"%@", [aView class]);
    NSLog(@"%@", [aView constraintsAffectingLayoutForAxis:1]);
    NSLog(@"%@", [aView constraintsAffectingLayoutForAxis:0]);

    [aView exerciseAmbiguityInLayout];
 }
}

Try that and see if you have any ambiguous layout. Of course do this after the rotation and everything is not right.

If that does not produce anything then just use the constraintsAffectingLayoutForAxis method on your specific view and you should see the constraint not allowing it to change.

Most likely there is a constraint with a too high priority that you will need to reduce.

于 2013-01-05T04:56:15.663 回答
0

I had to use inequalities. For example a text area width in portrait needs to be 100, but the landscape width needs to be >100 so it can stretch. Other constrains are in place to pull it to the sides already for me. I also enabled landscape modes. When I rotate now my 4 lines of text reflows to 2 lines very smartly.

于 2012-09-17T20:41:58.487 回答