【问题标题】:Hiding/Showing UINavigationBar causes UICollectionView to change it's frames隐藏/显示 UINavigationBar 会导致 UICollectionView 更改它的框架
【发布时间】:2016-03-16 09:02:58
【问题描述】:

我有 2 个 UIViewController,都连接到同一个 UINavigationController。我想隐藏第一个控制器的导航栏,但为第二个控制器显示它。对于这种行为,我使用以下代码:

override func viewWillAppear(animated: Bool) {
    self.navigationController?.setNavigationBarHidden(true, animated: false)
}

override func viewWillDisappear(animated: Bool) {
    self.navigationController?.setNavigationBarHidden(false, animated: false)
}

这会导致第二个控制器的 UICollectionView 在大约 0.5 秒后向下移动并出现黑色区域​​。灰色区域是集合视图,它的顶部约束链接到包含 UISegmentedControl 的视图。

控制台中的消息:

the behavior of the UICollectionViewFlowLayout is not defined because:
2016-03-15 17:26:58.829 Goku[56059:15539317] the item height must be less than the height of the UICollectionView minus the section insets top and bottom values, minus the content insets top and bottom values.
2016-03-15 17:26:58.830 Goku[56059:15539317] The relevant     UICollectionViewFlowLayout instance is <UICollectionViewFlowLayout:   0x7ffa28d49840>, and it is attached to <UICollectionView: 0x7ffa2a971000;   frame = (0 119; 375 548); clipsToBounds = YES; autoresize = RM+BM; gestureRecognizers = <NSArray: 0x7ffa28d5f950>; layer = <CALayer: 0x7ffa28d6e120>; contentOffset: {375, -64}; contentSize: {1125, 548}>   collection view layout: <UICollectionViewFlowLayout: 0x7ffa28d49840>.
2016-03-15 17:26:58.830 Goku[56059:15539317] Make a symbolic breakpoint at UICollectionViewFlowLayoutBreakForInvalidSizes to catch this in the debugger.

仅当我隐藏/显示导航栏时才会出现此消息,如果我不隐藏/显示,自动布局就可以正常工作。

将 UINavigationBar 的 translucency 属性设置为 false 会出于某种原因解决此问题,有没有办法在不更改 translucency 属性的情况下解决此问题?

【问题讨论】:

    标签: ios swift uicollectionview uinavigationbar


    【解决方案1】:

    您应该尝试取消选中 ViewController 的“调整滚动视图插入”复选框。 打开 Storyboard,选择 ViewController,转到 Attributes Inspector 并取消选中“Adjust Scroll View Inset”。

    【讨论】:

    • 没有为我解决问题
    猜你喜欢
    • 2014-06-26
    • 1970-01-01
    • 2011-03-11
    • 2016-07-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-02-24
    • 2014-04-23
    相关资源
    最近更新 更多