I have been trying the following such as pinning, aspect ratio, vertical spacing ,horizontal/vertical spacing,leading/trailing space; but it is not working uniformly for all iPhone screen from iPhone se and above.
问题:
回答1:
You dont apply constraints for each device anymore. You apply auto layout constraints per size class.
If you are aware each and every iOS devices falls under one of the size class in each orientation. If you aren't aware of size class do read about it.
As to answer your question, 1. You will add constraints which are common across all the size classes to any x any.
2.you can always add constraints specific to size class (What I mean is you can add constraints one size class while uninstall it in other size class if you dont want it)
3.you can select any of the constraint and provide it constant values, multipliers specific to size class (e.g.: you can set the height constraint constant to 50 in CxC while you can set it to 150 in (R x R) without adding a new constraint.
回答2:
By setting multipliers to correct value you can achieve this. I have tried non-programmatically and only in Xcode 8 :
- select one of the new view and hold ctrl & drag to the top most external view(or parent view) cause that changes with respect to different screen sizes.
- then hold shift and select multiple option as : 1)equal width & equal height, 2)center horizontally in container, 3) center vertically in container. As soon as this is done you will see yellow lines (around your new view) which tell about unsatisfied constraints.
- then select each constraints line(yellow coloured)or else select different constraints shown in view controller scene column and modify the multiplier until the yellow coloured line becomes blue i.e. until it satisfies the position where new view is needed to be in top most view or parent view.
screenshot showing multiplier for setting in Interface builder