gpt4 book ai didi

ios - UICollectionView 的透明 UINavigationBar 问题

转载 作者:行者123 更新时间:2023-11-30 13:34:14 26 4
gpt4 key购买 nike

我创建了一个简单的项目来测试如何使 UINavigationBar 透明。在这个项目中我有两个 UIViewController。第一个 View Controller 显示一个大按钮,它将第二个 View Controller 插入导航 Controller 。

第二个 View Controller 是一个 UIViewController,其中包含一个 UICollectioView(它不是 UICollectionViewController)。

在应用程序委托(delegate)中,我将此代码写入 application:didFinishLaunchingWithOptions

UINavigationBar.appearance().setBackgroundImage(UIImage(), forBarMetrics: .Default)
UINavigationBar.appearance().shadowImage = UIImage()
UINavigationBar.appearance().backgroundColor = UIColor(red: 0.0, green: 0.0, blue: 0.0, alpha: 0.0)
UINavigationBar.appearance().translucent = true

它对于第一个 UIViewController 来说就像一个魅力(导航栏是透明的),但是当我移动到另一个 UIViewController (带有 UICollectionView)时,导航栏不透明,当我回到上一个 UIViewController 时仍然不透明!

有什么建议吗?

PS:需要明确的是,我的预期结果是,即使我向上滚动并且它们在导航栏下方经过,我也希望看到单元格。不知道我说清楚了没有。

Storyboard

最佳答案

由于我没有 50 声誉,所以我无法评论这个问题,但我在 Xcode 中复制了您的项目,并且没有发现任何错误。我看到以下屏幕(注意半透明的导航栏):

First View Controller

Second View Controller

要创建这些屏幕,请执行以下操作,因此这可能是出现问题的地方:

  • 向 AppDelegate 添加代码
  • 在 NavigationController 中嵌入 FirstViewController
  • 添加 SecondViewController
  • 向 FirstViewController 添加按钮
  • 在“Button”和 SecondViewController 之间添加 Segue
  • 将 CollectionView 添加到 SecondViewController
  • 向“Button”和“CollectionView”添加约束

这可能听起来很愚蠢,但在 AppDelegate 中,您是否将代码放在:

return true

声明?

关于ios - UICollectionView 的透明 UINavigationBar 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36261290/

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