<legend id='xliRl'><style id='xliRl'><dir id='xliRl'><q id='xliRl'></q></dir></style></legend>

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

      <tfoot id='xliRl'></tfoot>

        • <bdo id='xliRl'></bdo><ul id='xliRl'></ul>

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

      1. 在代码中为 topLayoutGuide 和 bottomLayoutGuide 创建自动布局约束

        Creating Auto Layout constraints to topLayoutGuide and bottomLayoutGuide in code(在代码中为 topLayoutGuide 和 bottomLayoutGuide 创建自动布局约束)
        • <i id='Xo1wx'><tr id='Xo1wx'><dt id='Xo1wx'><q id='Xo1wx'><span id='Xo1wx'><b id='Xo1wx'><form id='Xo1wx'><ins id='Xo1wx'></ins><ul id='Xo1wx'></ul><sub id='Xo1wx'></sub></form><legend id='Xo1wx'></legend><bdo id='Xo1wx'><pre id='Xo1wx'><center id='Xo1wx'></center></pre></bdo></b><th id='Xo1wx'></th></span></q></dt></tr></i><div id='Xo1wx'><tfoot id='Xo1wx'></tfoot><dl id='Xo1wx'><fieldset id='Xo1wx'></fieldset></dl></div>

            <bdo id='Xo1wx'></bdo><ul id='Xo1wx'></ul>
          • <tfoot id='Xo1wx'></tfoot>
                <tbody id='Xo1wx'></tbody>

                <legend id='Xo1wx'><style id='Xo1wx'><dir id='Xo1wx'><q id='Xo1wx'></q></dir></style></legend>

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

                  本文介绍了在代码中为 topLayoutGuide 和 bottomLayoutGuide 创建自动布局约束的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  Apple 的 documentation 在视图和布局指南之一之间创建自动布局约束仅显示使用 VFL.

                  Apple's documentation on creating Auto Layout constraints between a view and one of the layout guides only shows an example using VFL.

                  有没有办法以编程方式创建这些约束没有 VFL(使用NSLayoutConstraint的其他API 或类似)?

                  Is there any way to create these constraints programmatically without VFL (using NSLayoutConstraint's other API or similar)?

                  (注意:我是专门询问在代码中执行此操作,而不是在 Interface Builder 中.而且我不希望将指南集的计算 length 设置为约束上的静态常量,我想要一个约束,其中对布局指南长度的更改会自动导致受约束的视图调整位置.)

                  (Note: I'm specifically asking about doing this in code, not in Interface Builder. And I don't want the calculated length of the guide set as a static constant on a constraint, I want a constraint where changes to the layout guide length would automatically cause the constrained view to adjust position.)

                  推荐答案

                  对于要在 UIViewController.topLayoutGuide 下方放置 20 点的 UIButton,请创建 NSLayoutConstraint 像这样:

                  For a UIButton that you want to place 20 points below the UIViewController.topLayoutGuide you create the NSLayoutConstraint like so:

                  [NSLayoutConstraint constraintWithItem:self.button
                                               attribute:NSLayoutAttributeTop
                                               relatedBy:NSLayoutRelationEqual
                                                  toItem:self.topLayoutGuide
                                               attribute:NSLayoutAttributeBottom
                                              multiplier:1.0
                                                constant:20.0];
                  

                  在 iOS 9 中,您还可以通过这种方式创建 NSLayoutConstraint:

                  With iOS 9 you can also create the NSLayoutConstraint this way:

                  [self.button.topAnchor constraintEqualToAnchor:self.topLayoutGuide.bottomAnchor
                                                        constant:20.0];
                  

                  这篇关于在代码中为 topLayoutGuide 和 bottomLayoutGuide 创建自动布局约束的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                  相关文档推荐

                  iOS AutoLayout - get frame size width(iOS AutoLayout - 获取帧大小宽度)
                  Auto layout constraints issue on iOS7 in UITableViewCell(UITableViewCell中iOS7上的自动布局约束问题)
                  How to resize superview to fit all subviews with autolayout?(如何调整超级视图的大小以适应所有具有自动布局的子视图?)
                  Springs in Auto Layout: Distribute views evenly, with constraints, in Xcode 5(自动布局中的弹簧:在 Xcode 5 中使用约束均匀分布视图)
                  reloadData() of UITableView with Dynamic cell heights causes jumpy scrolling(具有动态单元格高度的 UITableView 的 reloadData() 导致跳跃滚动)
                  What is NSLayoutConstraint quot;UIView-Encapsulated-Layout-Heightquot; and how should I go about forcing it to recalculate cleanly?(什么是 NSLayoutConstraint“UIView-Encapsulated-Layout-Height?我应该如何强制它干净地重新计算?) - IT屋-程序员
                    <i id='ZnyLt'><tr id='ZnyLt'><dt id='ZnyLt'><q id='ZnyLt'><span id='ZnyLt'><b id='ZnyLt'><form id='ZnyLt'><ins id='ZnyLt'></ins><ul id='ZnyLt'></ul><sub id='ZnyLt'></sub></form><legend id='ZnyLt'></legend><bdo id='ZnyLt'><pre id='ZnyLt'><center id='ZnyLt'></center></pre></bdo></b><th id='ZnyLt'></th></span></q></dt></tr></i><div id='ZnyLt'><tfoot id='ZnyLt'></tfoot><dl id='ZnyLt'><fieldset id='ZnyLt'></fieldset></dl></div>

                          <bdo id='ZnyLt'></bdo><ul id='ZnyLt'></ul>
                        • <tfoot id='ZnyLt'></tfoot><legend id='ZnyLt'><style id='ZnyLt'><dir id='ZnyLt'><q id='ZnyLt'></q></dir></style></legend>

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

                            <tbody id='ZnyLt'></tbody>