Swift 3:如何反转透明的导航栏? [英] Swift 3: How to reverse a transparent Navigation Bar?

查看:87
本文介绍了Swift 3:如何反转透明的导航栏?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用twitter API创建一个模拟真实应用程序的twitter应用程序.在时间轴视图上,我有一个常规的导航栏,当用户点击用户个人资料时,个人资料视图中有一个透明的栏,以便可以显示用户的横幅图像.我使用以下代码使导航栏在用户个人资料视图中透明:

I'm trying to create a twitter app, emulating the real app, using the twitter API. On the timeline view, I have a regular navigation bar, and when a user taps a user profile, the profile view has a transparent bar so that the user's banner image can be displayed. I used the following code to make the navigation bar transparent in the user profile view:

self.navigationController?.navigationBar.setBackgroundImage(UIImage(), for: .default)
self.navigationController?.navigationBar.shadowImage = UIImage()
self.navigationController?.navigationBar.isTranslucent = true

我遇到的问题是,当我从个人资料视图返回时,时间轴导航栏变得混乱了(下面的屏幕截图).我猜这是因为我更改了配置文件视图的视图控制器中导航栏的某些方面,而当我返回到时间轴视图时,这些方面仍然存在.

The problem I'm having is when I return from the profile view, the timeline navigation bar has become messed up (screenshots below). I'm guessing this is because I changed some aspects of the navigation bar in the view controller for the profile view, and that carried over when I returned to the timeline view.

我该如何反转导航栏的透明度以修复不正确的导航栏?在时间轴视图控制器中,我尝试使用以下代码尝试将其反转,但是它不起作用.

How can I reverse the navigation bar transparency to fix the wonky navigation bar? In the timeline view controller I've tried using the following code to try to reverse it, but it doesn't work.

self.navigationController?.navigationBar.setBackgroundImage(nil, for: .default)
self.navigationController?.navigationBar.shadowImage = nil
self.navigationController?.navigationBar.isTranslucent = false

带有常规导航栏的时间轴视图

带有透明导航栏的个人资料视图

带有不稳定导航栏的时间轴视图

推荐答案

我也发生了类似的情况.后来,我注意到我没有在正确的生命周期方法中更改导航项的属性.在时间轴视图控制器的viewWillAppear中使其不透明,并在离开时间轴视图控制器的viewWillDisappear中使其透明. 可能与此有关吗?

A similar case happened to me too. Later, I noticed that I didn't change the attributes of the navigation item in the right life cycle metod. Make it non-transparent, in viewWillAppear in timeline view controller and make it transparent before leave from the timeline view controller, in viewWillDisappear. Could it be related to that?

这篇关于Swift 3:如何反转透明的导航栏?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆