问题
I'm trying to create a layout that contains flexible vertical margins between specific elements of the static height in Interface Builder. Since I have no idea how I can define that, I tried using "spacer" views with flexible height. The layout I created in Interface Builder is the following:
The blue rectangles are the static height ones, and their height should not change. But their margins and spacing between them should change based on screen size. The red rectangles are the spacing views and are supposed to be with clear color, but I left them red, just for testing purposes.
First I created the layout using springs and struts. The achieved effect is almost correct, the spacers resize evenly, so I am satisfied, even though the red rectangles slightly overlap the blue ones, but since their purpose is only spacing, that would not be a problem. Even if they are removed, the effect is still the same.
Then I attempted to create the layout using auto layout, the most modern API for view placement. I pinned all vertical spacings and height of the blue rectangles. I also pinned the heights of the spacers, but set them to Less than or Equal. This is the result in Storyboard:
Auto layout is satisfied and no errors are displayed. The layout works okay for 4 inch devices, but when ran on a 3.5 inch device, this is the result:
So, the top and bottom red spacers are apparently of height 0, but the middle two spacers remain the same size. The priority of all height constraints of red rectangles is the same (default).
According to layman's logic, shouldn't all of the red rectangles resize by same multiplier, since their Less than or Equal priority is the same?
What is going on here and what am I doing wrong? Why I cannot achieve similar effect that can obviously be done using the springs and struts model?
Thank you for your help!
来源:https://stackoverflow.com/questions/21600539/ios-auto-layout-flexible-margins