简体   繁体   中英

AutoLayout Size Classes - different proportional heights

I need to set the height of a subview to be proportional to its parent. On iPads, I need it to be one third of the height while on iPhones I need it to be one half. In the "AnyAny" size class, I create the constraint and set the multiplier to 0.3333333. This does what it should on iPads. When I change the size class to "CompactRegular", I change the multiplier of the constraint to 0.5. Although this makes it half on iPhones, it also does it for iPads. How do I make it such that the size classes would have different multipliers?

You'll need to add a new constraint for Compact/Regular, and make sure the original one is only installed in Any/Any like so:

  • In Any/Any, add the original constraint (subview.height = superview.height * 0.33).
  • Switch to Compact/Regular, and select the previously added constraint.
  • In the size inspector, next to "installed", click the '+' button, and select Compact/Regular. Now You can disable "installed" in Compact/Regular (see pic).
  • Add the new constraint (subview.height = superview.height * 0.5), and make sure it's only installed in Compact/Regular mode.

尺寸检查员

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM