Set AutoLayout Size Class Programmatically?

前端 未结 3 1335
无人共我
无人共我 2020-12-28 19:25

With iOS 8 and Xcode 6, in storyboards we now have the screen size grid letting us select a size class. Where you can select layout formatting for the different screen sizes

3条回答
  •  温柔的废话
    2020-12-28 19:52

    iOS 8 introduces the active property on NSLayoutConstraint. It allows you to activate or deactivate a constraint. There are also methods to activate/deactivate multiple constraints.

    + (void)activateConstraints:(NSArray *)constraints
    + (void)deactivateConstraints:(NSArray *)constraints
    
    • Keep your constraints in arrays when creating them programmatically.
    • Create an array for each of the layouts you need.
    • Activate/Deactivate whatever set of constraints you need from within willTransitionToTraitCollection

提交回复
热议问题