iOS 11 large navigation bar title unexpected velocity iOS 11 large navigation bar title unexpected velocity swift swift

iOS 11 large navigation bar title unexpected velocity


I solved the problem with these constraints:

    NSLayoutConstraint.activate([        scrollView.topAnchor.constraint(equalTo: view.topAnchor),        scrollView.leftAnchor.constraint(equalTo: view.leftAnchor),        scrollView.bottomAnchor.constraint(equalTo: view.bottomAnchor),        scrollView.rightAnchor.constraint(equalTo: view.rightAnchor)        ])

You also have to set this property on your UIViewController subclass:

extendedLayoutIncludesOpaqueBars = YES


I found this problem as well.

In Interface Builder

  1. Select your "viewController"
  2. Attribute Inspector tick "Under Opaque Bars" and "Under Top Bars"
  3. Make your top constraints of your scrollView second Item to "SuperView" not "SafeArea"


I have been debugging this for a couple days, and I have found a workaround.

First, What Was Going On?

It is the UIScrollView that is not performing well with the largeTitle. Since there is scrolling up on the scroll view at the same time as the navigation bar becoming smaller, there exists twice the scrolling compared to the actual scroll.

I confirmed this by intentionally setting:

scrollView.contentOffset.y = scrollView.contentOffset.y * 0.5

This indeed made it move as desired. But, this couldn't solve the problem entire problem because it did not yield a smooth transition while going from large navigation bar to small navigation bar. You can try the below code out.

if scrollView.contentOffset.y > 0 {  if self.navigationController!.navigationBar.frame.size.height > 44.0 {    scrollView.contentOffset.y = scrollView.contentOffset.y * 0.5  }}

This worked 'okay' when scrolled slowly, but when you fling downward, it acts slow at first (while navigation height is large), and then speeds up afterwards.

WORKAROUND

Simply put, you CANNOT use UIScrollView with the iOS 11 large navigation bar. You ought to use UITableViewController instead.
Since my view is composed of multiple horizontal UICollectionViews spread along vertically, I used UITableView with different sections to form the UI using storyboard.If you use UITableViewController, it performs as desired.
AppStore and all other Apple-made native apps must do it this way.