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

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

    1. <tfoot id='DUYat'></tfoot>

      如何防止状态栏与 UINavigationController 上设置的 hidesBarsOnSwipe 内容重叠?

      时间:2023-05-17
    2. <legend id='L2oay'><style id='L2oay'><dir id='L2oay'><q id='L2oay'></q></dir></style></legend>

          <tbody id='L2oay'></tbody>

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

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

          <tfoot id='L2oay'></tfoot>
            <bdo id='L2oay'></bdo><ul id='L2oay'></ul>
                本文介绍了如何防止状态栏与 UINavigationController 上设置的 hidesBarsOnSwipe 内容重叠?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                限时送ChatGPT账号..

                我正在尝试使用 iOS 8 中添加的新功能 - 在用户滚动表格视图时隐藏导航栏(类似于移动 Safari 所做的).我在 UITableViewControllerviewDidAppear 方法中将 UINavigationController 的属性 hidesBarsOnSwipe 设置为 YES>:

                I'm trying to use the new feature added in iOS 8 - hiding the navigation bar while user is scrolling the table view (similar to what mobile Safari does). I'm setting the property hidesBarsOnSwipe of UINavigationController to YES in viewDidAppear method of UITableViewController:

                - (void)viewDidAppear:(BOOL)animated {
                    [super viewDidAppear:animated];
                    if([self.navigationController respondsToSelector:@selector(hidesBarsOnSwipe)]) {
                        self.navigationController.hidesBarsOnSwipe = YES;
                    }
                }
                

                滚动视图时导航栏隐藏.到现在为止还挺好.但是状态栏仍然可见,我的表格视图内容通过它显示出来,看起来很难看:

                The navigation bar hides when the view is being scrolled. So far so good. But the status bar is still visible and my table view contents show through it, which looks ugly:

                我尝试将 edgesForExtendedLayout 设置为 UIEdgeRectNone 或调整表格视图的 contentInset ,但没有帮助.是否有任何其他解决方案可以将状态栏与导航栏一起隐藏,或者使其不透明?

                I tried setting edgesForExtendedLayout to UIEdgeRectNone or adjusting the contentInset of the table view, but it didn't help. Is there any other solution to hide the status bar along with the navigation bar, or make it opaque?

                推荐答案

                基于 anas 的回答,我有一个可行的解决方案(我假设 tableViewController 是你的 UITableViewController实例):

                Building off of anas' answer, I have a working solution (I'm assuming tableViewController is your UITableViewController instance):

                UINavigationController 子类中(或者也可能来自 tableViewController):

                In a UINavigationController subclass (or also potentially from tableViewController):

                - (void)viewDidLoad {
                    if ([self respondsToSelector:@selector(barHideOnSwipeGestureRecognizer)]) {
                        // iOS 8+
                        self.hidesBarsOnSwipe = YES;
                        [self.barHideOnSwipeGestureRecognizer addTarget:self action:@selector(swipe:)];
                    }
                }
                
                - (void)swipe:(UISwipeGestureRecognizer *)recognizer {
                    BOOL shouldHideStatusBar = self.navigationController.navigationBar.frame.origin.y < 0;
                    tableViewController.hideStatusBar = shouldHideStatusBar;
                    [UIView animateWithDuration:0.2 animations:^{
                        [tableViewController setNeedsStatusBarAppearanceUpdate];
                    }];
                }
                

                在您的 tableViewController 中:

                @property(nonatomic, getter = shouldHideStatusBar) BOOL hideStatusBar;
                
                - (BOOL)prefersStatusBarHidden {
                    return [self shouldHideStatusBar];
                }
                

                如果这对您不起作用,请告诉我.一些不明显的事情:

                Let me know if this doesn't work for you. A few non-obvious things:

                • self.navigationController.navigationBar.frame.origin.y 隐藏时为-44(导航栏的负高度),可见时为20(状态栏的高度).即使在动画期间也没有中间值,因此负值 == 隐藏,非负值 == 可见.
                • 子视图控制器是查询状态栏是否应该隐藏的控制器.在我的例子中,我在 UITabBarControllerUINavigationController 中有一个 UIViewController,直到我覆盖 prefersStatusBarHiddenUIViewController 上.
                • 由于隐藏的状态栏没有框架,除非您将 setNeedsStatusBarAppearanceUpdate 调用封装在动画块中,否则您的内容可能会向上抖动 20 点.
                • 希望语法正确;我从我的 Swift 代码中反向移植了它.
                • self.navigationController.navigationBar.frame.origin.y was -44 (the negative height of the navigation bar) when hidden, and 20 (the height of the status bar) when visible. There was no in-between, even during animations, so a negative value == hidden and a nonnegative value == visible.
                • The child view controller is the one queried for whether or not the status bar should be hidden. In my case, I have a UIViewController within a UINavigationController within a UITabBarController, and it didn't work until I overrode prefersStatusBarHidden on the UIViewController.
                • Since a hidden status bar has no frame, your content might jerk upwards 20 points unless you wrap the call to setNeedsStatusBarAppearanceUpdate in an animation block.
                • Hopefully the syntax is correct; I backported this from my Swift code.

                这篇关于如何防止状态栏与 UINavigationController 上设置的 hidesBarsOnSwipe 内容重叠?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                <small id='7LftW'></small><noframes id='7LftW'>

              • <tfoot id='7LftW'></tfoot>

                  <tbody id='7LftW'></tbody>

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