1
votes

I've been trying to implement Apple Music like transparent navigation bar for pushed view controller. There are a lot of solutions on Internet saying place the code below into viewDidLoad:

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

But the thing is that it only works for root controller, e.g. UITableViewController with a list of items. When I tap on an item and open it's details I expect to see transparent navigation bar, but after appearing it becomes solid (not even translucent). Even setting barTintColor does not help.

What am i doing wrong? Or is it a known issue in iOS 11? It used to work before...

1

1 Answers

3
votes

I confirm that transparent navigation bar is not working in iOS 11 for pushed viewcontroller, instead just appears black without translucent @screenshot.

enter image description here

Firstly, I have filed this bug report, lastly :) I found a quick workaround that presenting and dismissing a UIViewcontroller fixes this issue, as following:

if (self.navigationController!.viewControllers.count > 1) {
    if #available(iOS 11.0, *) {
        self.present(UIViewController(), animated: true, completion: {
            self.dismiss(animated: false)
        })
        self.scrollView.contentInsetAdjustmentBehavior = .never
    } else {
        self.automaticallyAdjustsScrollViewInsets = false
    }
    self.extendedLayoutIncludesOpaqueBars = false
}

I am using above code in viewWillAppear and my UI is being generated programatically without storyboard or xib, so it works seamlessly :) and glad I get expected result @screenshot

enter image description here