问题
I have a UIViewController
set up in an UIStoryboard
in Interface Builder using size classes.
This looks good on an iPhone 5 with the 4" screen, but on the 5.5" screen of the iPhone 6 Plus the elements are too cramped in the top area of the device. I want to increase the constant of the spacing constraints on iPhone 6 and 6 Plus.
As far as I was able to see that's not possible with size classes, as there is only one size class for all iPhone displays (no matter if 3.5" or 5.5"). What is the way to do this? Maybe something with the constraint multiplier? Still haven't really figured that one out.
回答1:
See my answer here:
https://stackoverflow.com/a/20865342/341994
As I explain there, you can't make a spacing constraint value depend on the height of something. But you can make a height constraint depend on the height of something. So try adding an invisible view whose height is proportional to the superview height, and use it as a spacer, with constraints to it. This will push the views down proportionally to the screen height.
I made a quick demo. Look at how the top of the red view is further down on the iPhone 6 than it is on the iPhone 4s:
来源:https://stackoverflow.com/questions/27662051/autolayout-with-size-classes-different-spacing-depending-on-iphone-screen-size