简体   繁体   中英

iOS 14 large-title navigation bar doesn’t come back after shrinking

My large title does shrink normally when scrolled, just like it's supposed to. But, it doesn't come back large again even when I scroll to the top. When I build the project and open the app for the first time, the large title and search bar appear normally but once it shrinks. It doesn't come back before I finish the app. It happens the same on my device as well.

I am using tableView with ViewController , with searchBar in the navigation title . I also have tableview header under the navigation bar.

The way my large title works:

预览 1

The way it's supposed to work:

预览 1

I have added a searchController inside the navigation bar, but I don't think searchController is the problem because the same problem happens even when I remove the search bar from my project. Also, I have used the same code making large titles in those two different projects in the GIFs, but one works and one doesn't. Why is it?

I put this in the viewDidLoad() .

navigationController?.navigationBar.prefersLargeTitles = true

I also tried:

navigationItem.largeTitleDisplayMode = .always

But, it didn't work.

I also tried putting:

navigationController?.navigationBar.prefersLargeTitles = true
navigationItem.largeTitleDisplayMode = .always

those two in viewWillAppear() but it didn't work as well.

-Edit-

The tableView is the first in the view hierarchy, as well. Please let me know if there's something wrong with the hierarchy.

The image of my document outline:

预览 3

The possible problem is your tableview content height is almost same height of screen so it can't scroll and animates large title back. For that you can try always bounce function on your tableview. In viewDidLoad you can call

tableView.alwaysBounceVertical = true

Probably this will solve your problem if tableview is first view of viewcontroller subviews hierarchy.

I looked up what tableview.alwaysBounceVertical is and what bounce is in tableview , and I found out that bounceOnScroll property was set to false , which was the reason this problem occured(I guess). The large title becomes large again when I scroll to the top, after I checked true to bounce on scroll in the storyboard.

Also, the my large title works fine without setting bounce vertically property to true. I tried with both storyboard and in code by setting it to false. So the problem was with only bounceOnScroll , I guess.

In code, it is okay to put

tableview.bounces = true

on the viewController .

If you want the scrolling navigation bar to work correctly apart from the flag you set and the tableView position as first in view hierarchy you need to make sure that tableView top and bottom constraints are bind to superview. As default it's aligned to safe area which is incorrect.

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