简体   繁体   中英

iOS Swift Transition from normal navigation bar to transparent bar

在此处输入图片说明

I googled for similar issues, but none of them actually solves this. I tried to push from a view controller with normal navigation bar, to a new view controller with transparent navigation bar. This is the code in 2nd view controller that I used to set navigation bar transparent

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

How can I get a smooth transition without having a piece of light gray on navigation bar during transition?

What you need to do is to create a custom navigation bar and use it instead. It will look much better. I have had similar issues and the only thing that solved it for me was to create the custom navigation bar. Go to your Storyboard and add it:

在此处输入图片说明

I'm attaching a sample project for your reference, everything is setup via storyboard, no code. Hope it helps!

file link

Here's what the project achieves, on the viewController showing the button, the navigation bar is visible, and when the button is clicked, another viewController is pushed into view, but the navigation bar is hidden completely from view. It only appears when the user taps anywhere within the view.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM