iOS 11 issues with navigationBar prefersLargeTitles
Asked Answered
R

4

22

Xcode 9 beta 6 iOS 11

I have a storyboard for a viewController, the background ImageView, tableView and the searchFooter view are the subViews of the view.The structure is as follows:

enter image description here

In the AppDelegate class,I set
UINavigationBar.appearance().prefersLargeTitles = true

and

UINavigationBar.appearance().setBackgroundImage(UIImage(),for: .default)

UINavigationBar.appearance().shadowImage = UIImage()

In the viewControllerclass,I set navigationItem.searchController = searchController and navigationItem.hidesSearchBarWhenScrolling = true

When I run the application, I found that the shadowImage of the navigationBar was still exist. The navigationBar wouldn't become normal(not the prefersLargeTitles mode ) automatically(the left gif) when I scrolled the tableView.I hope the navigationBar can work just like the system app(the right gif).

my appsystem app

A weird behavior: When I remove the background imageView, it can work as well as the system app on the simulator.

I don't know why it happened,I wonder how to solve it? Thanks.

Roborant answered 1/9, 2017 at 4:50 Comment(2)
That looks like an iOS/UIKit bug, try reporting it to Apple.Averir
I just found that the tableview has to be the first subview in the view hierarchy. Still try to see if there is a way to work around.Tarnopol
B
2

I've made a small application for your issue. You can reach the project on Github.

Transparent NavigationBar for iOS11

Note: You must use a color for UINavigationBar when scrolling up.

Bidget answered 1/11, 2017 at 13:42 Comment(2)
I'm the original author of this question, this's my new ID.I downloaded the project you provided, it indeed can fix the issue.But one question, why must use a color for UINavigationBar when scrolling up?Any apple docs mention this?Thanks.Philip
I took a look at the code in your project,you set the tableView.backgroudView = UIImageView(image: UIImage(named: "main_background")).Actually ,the situation isn't the same.I used a UIImageView under the tableView instead of setting a backgroudView.You can download my project with the linkPhilip
P
0

The account has been deleted by Stack overflow team. So I use my another ID to comment here. I have reported the issue to Apple,they asked me to provide a project and I did, but no more further comment from Apple.

Philip answered 26/9, 2017 at 3:19 Comment(0)
S
0

Make your TableView Top constraint right under NavigationController's NavigationsBar, not ViewControllers Top. It should work

Squirmy answered 20/11, 2017 at 3:11 Comment(0)
S
-1

You should add below line in viewDidLoad()

self.navigationController?.navigationBar.prefersLargeTitles = true
navigationItem.hidesSearchBarWhenScrolling = false

OR YOU CAN implement viewForHeaderInSection method of UITableViewDataSource

func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? 
    {
            let search = UISearchController(searchResultsController: nil)
            search.searchResultsUpdater = self
            return search.searchBar
    }

Link to see the screenshot 1 Link to see the screenshot 2

Scissel answered 9/9, 2017 at 21:53 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.