Auto Layout: Square Image View with equal width / height

亡梦爱人 提交于 2019-12-08 08:45:02

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!