gpt4 book ai didi

ios - 隐藏/显示 UINavigationBar 会导致 UICollectionView 更改其框架

转载 作者:搜寻专家 更新时间:2023-11-01 06:40:31 24 4
gpt4 key购买 nike

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

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

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

这会导致第二个 Controller 的 UICollectionView 在大约 0.5 秒后向下移动并出现黑色区域​​。灰色区域是 Collection View ,其顶部约束链接到包含 UISegmentedControl 的 View 。

控制台中的消息:

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 的半透明属性设置为 false 可以解决这个问题,有没有办法在不更改半透明属性的情况下解决这个问题?

最佳答案

您应该尝试取消选中 ViewController 的“Adjust Scroll View Inset”复选框。打开 Storyboard,选择 ViewController,转到 Attributes Inspector 并取消选中“Adjust Scroll View Inset”。

enter image description here

关于ios - 隐藏/显示 UINavigationBar 会导致 UICollectionView 更改其框架,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36030954/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com