Autolayout and proportional positioning

我是研究僧i 提交于 2019-12-23 21:05:56

问题


I suppose that my situation should be a common problem, but I'm really new to AutoLayout and to me it seems particularly complicated:

I want to make a layout to be suitable with 3.5 inches and 4 inches screens. This is the view for 4 inches displays:

And here is the view for a 3.5 inches display:

What I need is essentially make the spaces between the segmented control and the yellow and blue view proportional to the screen size I suppose.

My solution (that doesn't work):

1)Adding constraints for top/bottom vertical spaces of the segment control using less or equal to.

2)Adding constraints to the other views to keep their positions (for example the blue view has a bottom spacing to the main view equal to zero, the yellow view has a fixed top spacing).

In my mind the constraints of point 1) just scale down when the main view scales... but it doesn't happen... and the segment view just move behind the other views maintaining the spacing defined as max value of the "Less then or equal to" definition.

How can I solve this common problem?

Have I to create spacer views for this situation? and in that case how you'd set up them?


回答1:


There is an pure autolayout solution:

  1. Add vertical space constraint [yellowView]-(80@500)-[segmentView]
  2. Add second vertical space constraint [segmentView]-(>=5)-[blueView]


来源:https://stackoverflow.com/questions/20192907/autolayout-and-proportional-positioning

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