本文介绍了在 NavigationBar Hide on Swipe 之后,单元格出现在 HeaderCell & 之间状态栏一秒钟的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试添加 AppDelegate DidFinishLaunch..

I tried adding in AppDelegate DidFinishLaunch..

let view: UIView = UIView.init(frame: CGRectMake(0, 0, UIScreen.mainScreen().bounds.size.width, 25))
view.backgroundColor = UIColor.redColor()
view.alpha = 1
self.window!.rootViewController!.view.addSubview(view)

在我将状态栏更改为红色后,我阻止它进入状态栏下方,但我意识到它不仅仅是状态栏,而且导航栏在被滑动时发生了一些事情.在 NavBar 被刷掉 1 秒后,内容单元格才会显示.1 秒后,一切看起来都很好,没有内容单元格越过标题单元格或状态栏.

After I changed the Status Bar to red, I prevented it going under status bar, but I realised that it wasn't just the Status Bar and there was something going on with the Navigation Bar while it gets swiped away. The content cells get shown until 1 seconds after NavBar gets swiped away. After 1 seconds, everything seem nice and no content cell gets over the header cell or status bar.

为了解决这个问题,在Navigation Bar滑动的时候,Header Cell和状态栏之间有一个gap form,所以content cell出现了1秒.

但是我怎样才能防止这个 1-2 秒的错误呢?标题单元格提供了 1-2 秒的间隙.如果我快速向下滑动/滚动表格视图,通常会发生这种情况.

But how can I prevent this 1-2 second bug? It's the header cell that gives a gap for 1-2 seconds. It mostly occur if I swipe/roll the table view down fast.

我将下面的原始问题留给未来的读者.

I am leaving the original question below for the future readers.

原始问题:

我有一个带有 Header & 的 TableViewController内容单元格.我在滑动时隐藏导航控制器.但是,隐藏导航栏后,内容单元格的内容位于顶部的状态栏下方.其他一切都很好.

I have a TableViewController that has Header & Content cells. I am hiding Navigation Controller on Swipe. However, after hiding Nav Bar, Content cells' content goes under the status bar at the top. Everything else is fine.

标题单元格看起来不错,因为它们就在状态栏下方.

Header Cells seem fine, as they stop right below Status Bar.

  • Extend Edges - Top Bars 应检查标题单元格以停止进入状态栏,但不幸的是不会停止内容单元格.

我试过了:

  • self.tableView.contentInset = UIEdgeInsetsMake(20, 0, 0, 0).然而,这在 Header Cell & 之间给出了一个空间.状态栏(甚至在导航栏隐藏之前).我想在隐藏导航栏后实现.

  • self.tableView.contentInset = UIEdgeInsetsMake(20, 0, 0, 0).However, this gives a space between Header Cell & Status Bar (even before the Navigation Bar gets hidden). I want to achieve after hiding the Nav Bar.

self.extendedLayoutIncludesOpaqueBars = false 什么都不做.

self.automaticallyAdjustsScrollViewInsets = false 使用此方法将 HeaderCell 锚定到视图顶部,以便 HeaderCell 定位在 NavigationBar 下.

self.automaticallyAdjustsScrollViewInsets = false Using this anchors the HeaderCell to the top of the view so HeaderCell gets positioned under NavigationBar.

self.edgesForExtendedLayout = UIRectEdge.None.使用这使得 HeaderCell 位置本身从状态栏的顶部开始,所以标题的一半似乎在状态栏下.(还有导航栏 - Bar Tint 强制变成暗灰色,忽略我选择的任何内容,所以不太方便)

self.edgesForExtendedLayout = UIRectEdge.None. Using this made the HeaderCell position itself starting from the top of Status Bar so half of the Header seems under status bar. (Also Navigation Bar - Bar Tint forces to become dull gray ignoring whatever I choose, so not really convenient)

我想问

  • 有没有办法不让状态栏不透明&使它坚固?(我在 Storyboard 上有 Status Bar - Inherred).

否则,有没有办法防止这种行为?也许考虑状态栏固体;或者可能在导航栏隐藏后给标题单元格一个空间或位置 HeaderCell 从状态栏下方开始?

Otherwise, is there a way to prevent this behaviour? Maybe considering status bar solid; or maybe giving the Header Cell a space or position HeaderCell starting under the Status bar after the Navigation Bar gets hidden?

推荐答案

我没能通过 TableViewController 获得它,这是我的解决方法...

I had no luck getting it with TableViewController, here is my workaround...

  • 创建了一个新的 ViewController

  • Created a new ViewController

未选中调整滚动视图插入"

Unchecked 'Adjust Scroll View Insets'

将TableView 从TableViewController 复制到ViewController 的View 中.

Copied the TableView from TableViewController into ViewController's View.

向 TableView 添加约束(上/下/左 -20/右 20).

Added constraints to TableView (Top/Bottom/Left -20/Right 20).

在 AppDelegate 中,将状态栏设为白色.

In AppDelegate, give white colour to Status Bar.

这篇关于在 NavigationBar Hide on Swipe 之后,单元格出现在 HeaderCell & 之间状态栏一秒钟的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

11-02 13:04