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

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

      状态栏在旋转时隐藏时调整视图

      时间:2023-09-11

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

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

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

              • 本文介绍了状态栏在旋转时隐藏时调整视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                我四处寻找这个问题的答案,但我只找到了有类似问题的人,而不是这个确切的问题,所以希望这里有人可以帮助我!

                I've browsed around looking for an answer for this, but I've only found people with similar problems and not this exact problem, so hopefully someone here can help me!

                我有一个 iPad 应用程序.在 iPad 上,当您以纵向或横向握持 iPad 时,始终会显示带有时钟和电池的状态栏.出于这个原因,我的一些视图控制器的顶部有一些自定义工具栏,它们占了这 20 点.

                I have an iPad App. On iPad, when you hold the iPad in either portrait or landscape, the status bar with the clock and battery is always shown. For this reason, I have some custom toolbars at the top of some of my View Controllers that account for those 20 points.

                我现在正在努力使我的应用程序具有通用性.我注意到的第一件事是,当 iPhone 在纵向模式下显示状态栏时,会显示状态栏,但在横向模式下,状态栏会隐藏,现在我有一个高 20 磅的工具栏.

                I am now working on making my App universal. The first thing I noticed is that when the iPhone is help in portrait mode the status bar is shown, but when it's held in landscape mode, the status bar hides and now I have a toolbar that is 20 points too tall.

                我对总是隐藏或总是显示状态栏不感兴趣.我认为在手机的横向模式下隐藏它的功能很好.我想要做的是能够检测到状态栏何时隐藏,以便我可以调整工具栏的 Y 位置(因此将其设为 0 或 -20).一个更好的解决方案是,如果我有办法设置布局约束来处理这种情况.

                I am not interested in either always hiding or always showing the status bar. I think the functionality of hiding it on landscape mode on the phone is fine. What I want to do is to be able to detect when the status bar is hidden so that I can adjust the Y position of my toolbar (so make it either 0 or -20). An even better solution would be if there's a way for me to set my layout constraints to handle this scenario.

                推荐答案

                正确的做法是:

                • 使用具有正常高度的正常工具栏 - 不要对高度设置任何限制.

                • Use a normal toolbar with a normal height - do not set any constraint on the height.

                将前导约束 0 添加到父视图(不是父视图边距),将尾随约束 0 添加到父视图(不是父视图边距).

                Add leading constraint 0 to superview (not superview margin), trailing constraint 0 to superview (not superview margin).

                将顶部约束 0 添加到顶部布局指南(或安全区域顶部).这似乎会在工具栏上方留出 20 像素的空间,但要笑一个邪恶的笑,然后继续.

                Add top constraint 0 to top layout guide (or top of safe area). This will appear to leave 20 pixels of space above the toolbar, but laugh an evil laugh and proceed.

                将视图控制器设置为工具栏的委托(为此有一个委托出口).

                Set the view controller as the toolbar's delegate (there is a delegate outlet for this purpose).

                让视图控制器采用 UIBarPositioningDelegate 并实现委托方法如下:

                Have the view controller adopt UIBarPositioningDelegate and implement the delegate method as follows:

                class ViewController: UIViewController, UIBarPositioningDelegate {
                    func position(for bar: UIBarPositioning) -> UIBarPosition {
                        return .topAttached
                    }
                }
                

                当有状态栏时,这将导致工具栏的外观高度在状态栏后面向上延伸,但当没有状态栏时,它将具有正常高度并与顶部相撞.

                This will cause the apparent height of the toolbar to be extended up behind the status bar when there is a status bar, but it will have normal height and be smack against the top when there is no status bar.

                这篇关于状态栏在旋转时隐藏时调整视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                上一篇:自动布局以编程方式修改约束乘数 下一篇:带有customView的自动布局iOS 11工具栏UIBarButtonItem

                相关文章

                1. <tfoot id='2z2RE'></tfoot>

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

                2. <small id='2z2RE'></small><noframes id='2z2RE'>

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