问题
The title might seem a bit complicated so I'll just show you what I want in some pictures.
So here is what I want:
[1] - http://i.stack.imgur.com/5Vckr.png
And here is how I tried to accomplish it in xCode 6:
[2] - http://i.stack.imgur.com/ags9s.png
[3] - http://i.stack.imgur.com/UhIuy.png
As you can see I tried to use size classes to snap the ImageView to the left and right in portrait view and to the bottom and top in landscape. But somehow it is not aligned right in Landscape and if I look at a iPad preview the ImageView does not show up at all. This probably is pretty simple but I tried for hours and still have no result.
Thank you for your help!
回答1:
First of all switch mode from w:Compact/h:Any to w:Any/h:Any. By adding constraints in this mode you will apply them for all devices and orientations.
Here is list of constraints that you need to apply:
Set lower priority (e.g. 750) for the two constraints with the dashed border (Equal Width and Equal Height to superview), and let the others have default priority of 1000.
来源:https://stackoverflow.com/questions/28614454/auto-layout-square-image-view-with-equal-width-height