问题
I've recently been encountering a difference in the regular / regular sizing class among different iPads, here's my related question Regular / Regular position sizing constraints for all iPads, including iPad pro?
Although I can use a multiplier and a constant to provide a margin, which is based on the device height, I can't now apply this approach to the spacing between views. Obviously, because I'm create a constraint between two views and can't therefore add the device height aka superview into the constraint.
I'm faced with having to add a clear / blank spacing view which is proportional height to the superview and pin my two views above and below it.
I'm looking for a different approach, is there one I'm not aware of?
回答1:
I tried it this way:
In the below example I have two views. And I want spacing between them. The constriants on both views are.
view1:
- Top space
- Leading
- Trailing
- Proportional Height to superview(View1.height = 45% superview.height)
View2:
- Leading, Trailing, Bottom, Proportional Height to Superview(View2.height = 45% superView.height)
Here I did not fix the spacing between them. So Spacing will be different on different screen sizes.
So you divide your views heights in such a way that create spaces between them automatically.
This is one way. The other way is to use priority and greater then or equal to, less then or equal to, type of constraints.
Result on different devices:
IPHONE
IPAD 2 (50 % Zoom level)
IPAD PRO (50 % Zoom level)
回答2:
Doh, all I'd need to do is follow the same approach as the other answer, and treat the top of the lower view as the top view. Then if I had problem with the top view views and lower view crashing into each other, then I could add a constraint with a priority.
来源:https://stackoverflow.com/questions/34225308/regular-regular-spacing-between-views-for-all-ipads-and-ipad-pro