0

I've got a tableView which is inside a view controller which is embedded in a navigation controller.

I want to customize the way the large title navigation bar shrinks to a small navigation bar. Normally, when you scroll to the top of a tableView, the small title expands to a large title. However, I need the large title to be always visible until you scroll past a certain cell. In the example gif, you see that the navigation bar shrinks / expands according to the position of the orange cell. You can see that there are many other blue cells on top of the orange cell, where the large title is always visible.

What I tried so far:

According to this answer, I tried adding a helper view, which prevents the navigation bar from collapsing. This worked, but now I need to figure out how to make this dynamic, so the large title would animate after a certain scroll position.

I tried using UIScrollViewDelegate:

func scrollViewDidScroll(_ scrollView: UIScrollView) {
    if scrollView.contentOffset.y >= 500 {
        self.view.insertSubview(helperView, aboveSubview: tableView)
    } else {
        self.view.insertSubview(helperView, belowSubview: tableView)
    }
}

But this did not work, the navigation bar did not collapse dynamically. Just after you went to another app and switched back tho my app, the navigation bar changed its size.

enter image description here

Do you know of a better way to make the large title collapse / expand according to a certain scroll point and not the top of a table view? Maybe some way of subclassing the navigationBar?

WalterBeiter
  • 2,021
  • 3
  • 23
  • 48

0 Answers0