设置自动版式径级编程方式? [英] Set AutoLayout Size Class Programatically?

查看:116
本文介绍了设置自动版式径级编程方式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用的iOS 8和X code 6,在故事板,我们现在拥有的屏幕尺寸格栅让我们选择一个尺寸级别。在这里你可以选择布局格式为不同的屏幕尺寸。

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.

我发现这个精辟有用,因为它可以让我设置基本约束条件,然后那些独特的每个屏幕尺寸。

I have found this brilliantly helpful, as it allows me to set the base constraints and then unique ones for each screen size.

我的问题是,你能做到这一点编程?我创建 NSLayoutConstraint 正常,但我需要能够指定不同的屏幕大小不同的约束。

My question is, can you do this programmatically? I create my NSLayoutConstraint as normal but I need to be able to specify different constraints for different screen sizes.

推荐答案

的iOS 8引入了<一个href=\"https://developer.apple.com/library/ios/documentation/AppKit/Reference/NSLayoutConstraint_Class/index.html#//apple_ref/doc/uid/TP40010628-CH1-DontLinkElementID_6\"><$c$c>active NSLayoutConstraint财产。它允许您激活或停用的约束。也有方法来激活/关闭多个约束。

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


  • 以编程方式创建他们的时候让你的约束阵列。

  • 创建每个你所需要的布局数组。

  • 激活/停用你在 willTransitionToTraitCollection 需要的任何约束集

    • 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
    • 这篇关于设置自动版式径级编程方式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆