Multiple UIVIew Autolayout issue

2019-09-08 04:45发布

问题:

I have an UIViewController with four subviews its look like below picture first subview is 50% of the screen and remaining three subviews occupy the remaining 50% of the view.In the bottom first 25% its will occupy the 2:1 ratio range.remains are occupy by 25% of the view.it's will be positioning the ipad landscape view properly but in portrait view first view more than 70% occupy. how to resolve this

回答1:

I've created the setup according to what you want. Please check the below screenshots.

Here are the steps to create this setup:
1. Add the four views into the main view.
2. Add leading, top and trailing space constraints from the brown view to the main view.
3. Add vertical spacing and leading constraints from the purple view to the brown view.
4. Add vertical spacing, trailing and equal heights constraints from the green view to the brown view.
5. Add bottom space constraint from the green view to the main view.
6. Add horizontal spacing and equal widths constraints from the purple view to the green view.
7. Add vertical spacing, leading, trailing and equal heights constraint from the orange view to the purple view. Change the multiplier value of this equal heights constraint from 1 to 0.5 in the size inspector (See the last screenshot).
8. Add bottom constraint from the orange view to the green view.

1. Views in Storyboard:


2. View Hierarchy and Constraints:


3. iPad Screenshot in Portrait:


4. iPad Screenshot in Landscape:


5. Size Inspector: