1. <tfoot id='amtZX'></tfoot><legend id='amtZX'><style id='amtZX'><dir id='amtZX'><q id='amtZX'></q></dir></style></legend>

    <small id='amtZX'></small><noframes id='amtZX'>

      <bdo id='amtZX'></bdo><ul id='amtZX'></ul>

    <i id='amtZX'><tr id='amtZX'><dt id='amtZX'><q id='amtZX'><span id='amtZX'><b id='amtZX'><form id='amtZX'><ins id='amtZX'></ins><ul id='amtZX'></ul><sub id='amtZX'></sub></form><legend id='amtZX'></legend><bdo id='amtZX'><pre id='amtZX'><center id='amtZX'></center></pre></bdo></b><th id='amtZX'></th></span></q></dt></tr></i><div id='amtZX'><tfoot id='amtZX'></tfoot><dl id='amtZX'><fieldset id='amtZX'></fieldset></dl></div>

      以编程方式设置 AutoLayout 大小类?

      Set AutoLayout Size Class Programmatically?(以编程方式设置 AutoLayout 大小类?)
      <tfoot id='BIbsv'></tfoot>
      <legend id='BIbsv'><style id='BIbsv'><dir id='BIbsv'><q id='BIbsv'></q></dir></style></legend>

            <tbody id='BIbsv'></tbody>

          <small id='BIbsv'></small><noframes id='BIbsv'>

            <bdo id='BIbsv'></bdo><ul id='BIbsv'></ul>

                <i id='BIbsv'><tr id='BIbsv'><dt id='BIbsv'><q id='BIbsv'><span id='BIbsv'><b id='BIbsv'><form id='BIbsv'><ins id='BIbsv'></ins><ul id='BIbsv'></ul><sub id='BIbsv'></sub></form><legend id='BIbsv'></legend><bdo id='BIbsv'><pre id='BIbsv'><center id='BIbsv'></center></pre></bdo></b><th id='BIbsv'></th></span></q></dt></tr></i><div id='BIbsv'><tfoot id='BIbsv'></tfoot><dl id='BIbsv'><fieldset id='BIbsv'></fieldset></dl></div>

                本文介绍了以编程方式设置 AutoLayout 大小类?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                在 iOS 8 和 Xcode 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 引入了 NSLayoutConstraint 上的 html#//apple_ref/doc/uid/TP40010628-CH1-DontLinkElementID_6" rel="noreferrer">active 属性.它允许您激活或停用约束.还有一些方法可以激活/停用多个约束.

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

                    本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                相关文档推荐

                iOS AutoLayout - get frame size width(iOS AutoLayout - 获取帧大小宽度)
                How to resize superview to fit all subviews with autolayout?(如何调整超级视图的大小以适应所有具有自动布局的子视图?)
                quot;Auto Layout still required after executing -layoutSubviewsquot; with UITableViewCell subclass(“执行 -layoutSubviews 后仍需要自动布局带有 UITableViewCell 子类)
                How do I animate constraint changes?(如何为约束更改设置动画?)
                How do I size a UITextView to its content?(如何根据内容调整 UITextView 的大小?)
                How to change the preferred language of an iPhone app in iOS 4(如何在 iOS 4 中更改 iPhone 应用程序的首选语言)

                    <tbody id='kNOVQ'></tbody>

                    <legend id='kNOVQ'><style id='kNOVQ'><dir id='kNOVQ'><q id='kNOVQ'></q></dir></style></legend>
                  1. <i id='kNOVQ'><tr id='kNOVQ'><dt id='kNOVQ'><q id='kNOVQ'><span id='kNOVQ'><b id='kNOVQ'><form id='kNOVQ'><ins id='kNOVQ'></ins><ul id='kNOVQ'></ul><sub id='kNOVQ'></sub></form><legend id='kNOVQ'></legend><bdo id='kNOVQ'><pre id='kNOVQ'><center id='kNOVQ'></center></pre></bdo></b><th id='kNOVQ'></th></span></q></dt></tr></i><div id='kNOVQ'><tfoot id='kNOVQ'></tfoot><dl id='kNOVQ'><fieldset id='kNOVQ'></fieldset></dl></div>

                      <bdo id='kNOVQ'></bdo><ul id='kNOVQ'></ul>
                      <tfoot id='kNOVQ'></tfoot>
                      • <small id='kNOVQ'></small><noframes id='kNOVQ'>