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

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

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

        iOS 在设备旋转时更改自动布局约束

        iOS change auto layout constraints when device rotates(iOS 在设备旋转时更改自动布局约束)
        <i id='3iUKu'><tr id='3iUKu'><dt id='3iUKu'><q id='3iUKu'><span id='3iUKu'><b id='3iUKu'><form id='3iUKu'><ins id='3iUKu'></ins><ul id='3iUKu'></ul><sub id='3iUKu'></sub></form><legend id='3iUKu'></legend><bdo id='3iUKu'><pre id='3iUKu'><center id='3iUKu'></center></pre></bdo></b><th id='3iUKu'></th></span></q></dt></tr></i><div id='3iUKu'><tfoot id='3iUKu'></tfoot><dl id='3iUKu'><fieldset id='3iUKu'></fieldset></dl></div>
        • <bdo id='3iUKu'></bdo><ul id='3iUKu'></ul>

          1. <tfoot id='3iUKu'></tfoot>
              <tbody id='3iUKu'></tbody>

                • <legend id='3iUKu'><style id='3iUKu'><dir id='3iUKu'><q id='3iUKu'></q></dir></style></legend>

                  <small id='3iUKu'></small><noframes id='3iUKu'>

                  本文介绍了iOS 在设备旋转时更改自动布局约束的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我想在设备旋转时修改布局约束.我的 UIViewController 由 2 个 UIViews 组成,横向对齐,在纵向中,它们是垂直对齐的.

                  I want to modify the layout constraints when the device rotates. My UIViewController is composed of 2 UIViews, in landscape they are horizontally aligned, and in portrait they are vertically aligned.

                  它确实有效,在 willAnimateRotationToInterfaceOrientation 中,我删除了所需的约束并用其他约束替换它们以获得正确的布局...

                  It does work actually, in willAnimateRotationToInterfaceOrientation, I remove the desired constraints and replaced them with others to have the right layout...

                  但是有问题,在旋转期间,自动布局在调用 willAnimateRotationToInterfaceOrientation 之前开始打破约束,那么当设备重新定向发生时,我们打算在哪里替换我们的约束?

                  But there are problems, during rotation auto layout starts breaking constraints before willAnimateRotationToInterfaceOrientation is called, so where are we meant to replace our constraints when the device reorientation occurs ?

                  另一个问题是性能,经过几次旋转后,系统不再打破限制,但我的性能下降很大,尤其是在纵向模式下...

                  Another issue is performance, after a few rotations the system doesn't break anymore constraints, but I have a huge performance drop, especially in portrait mode...

                  推荐答案

                  willRotateToInterfaceOrientation:duration: 中,将 setNeedsUpdateConstraints 发送到任何需要修改其约束的视图.

                  In willRotateToInterfaceOrientation:duration:, send setNeedsUpdateConstraints to any view that needs its constraints modified.

                  或者,创建一个 UIView 子类.在您的子类中,注册以接收 UIApplicationWillChangeStatusBarOrientationNotification.当您收到通知时,向自己发送 setNeedsUpdateConstraints.

                  Alternatively, make a UIView subclass. In your subclass, register to receive UIApplicationWillChangeStatusBarOrientationNotification. When you receive the notification, send yourself setNeedsUpdateConstraints.

                  这会在视图上设置 needsUpdateConstraints 标志.在系统执行布局之前(通过发送 layoutSubviews 消息),它会向任何设置了 needsUpdateConstraints 标志的视图发送 updateConstraints 消息.这是您应该修改约束的地方.创建一个 UIView 子类并覆盖 updateConstraints 以更新您的约束.

                  This sets the needsUpdateConstraints flag on the view. Before the system performs layout (by sending layoutSubviews messages), it sends an updateConstraints message to any view that has the needsUpdateConstraints flag set. This is where you should modify your constraints. Make a UIView subclass and override updateConstraints to update your constraints.

                  这篇关于iOS 在设备旋转时更改自动布局约束的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                  相关文档推荐

                  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屋-程序员

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

                  • <small id='preHy'></small><noframes id='preHy'>

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

                          <tfoot id='preHy'></tfoot>
                            <tbody id='preHy'></tbody>