【问题标题】:Transclucent navigation bar moving section header半透明导航栏移动部分标题
【发布时间】:2015-12-02 22:48:41
【问题描述】:

我只是一个努力获得半透明导航栏的简单人。 我试图在 appDelegate 和特定的 ViewController 中设置它。 我最终得到的是: 有谁知道为什么白色的部分标题被向下移动?当我滚动时,导航栏甚至不是半透明的,我无法为其设置颜色。 (当 translucent = false 时我可以设置颜色) 我试图将它设置为半透明和不透明,并在情节提要中推断出来。(不工作)

更新:

let colorImage = imageFromColor(UIColor(red:0.22, green:0.23, blue:0.29, alpha:0.5), frame: CGRectMake(0, 0, 340, 64))
self.navigationController!.navigationBar.setBackgroundImage(colorImage, forBarMetrics: UIBarMetrics.Default)
self.navigationController!.navigationBar.shadowImage = colorImage
self.navigationController!.navigationBar.translucent = true

colorImage 是我用 rgb-uicolor 制作的图像。结果是这样的:navigation bar 2

section header之间是半透明的,但是top bar不是!

UPDATE 2

【问题讨论】:

  • 在 SO 中快速搜索会给你很多关于这个主题的结果。看看这个链接,stackoverflow.com/questions/20319439/…
  • 请回复。我已经在我的viewController和appDelegate中试过了,结果和图片一样!
  • 请提供代码,方便调试。
  • 覆盖 func viewWillAppear(animated: Bool) { super.viewWillAppear(animated) self.navigationController!.navigationBar.setBackgroundImage(colorImage, forBarMetrics: UIBarMetrics.Default) self.navigationController!.navigationBar.shadowImage = colorImage self.navigationController!.navigationBar.translucent = true }
  • 您是想为您的navigationBar 显示一个自定义shadowImage,还是仅仅因为它在代码中被提及?注释掉那行代码后检查

标签: ios objective-c xcode swift uinavigationbar


【解决方案1】:

如果您尝试在您的应用程序中为navigationBar 设置半透明背景,您可以在AppDelegateapplication:didFinishLaunchingWithOptions 方法中使用以下代码

let colorImage = getImageWithColor(UIColor(red:0.22, green:0.23, blue:0.29, alpha:0.5), size: CGSizeMake(360, 64))
UINavigationBar.appearance().setBackgroundImage(colorImage, forBarMetrics: UIBarMetrics.Default)
UINavigationBar.appearance().translucent = true
UINavigationBar.appearance().tintColor = UIColor.whiteColor()

结果截图:

【讨论】:

  • 如果我没有两个相互重叠的导航栏,这将是完美的!
  • 为什么会有两个导航栏?你想达到什么目的?
  • 我的问题是我有两个,不知道为什么。我只想要一个!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多