andreamazz / AMScrollingNavbar

Scrollable UINavigationBar that follows the scrolling of a UIScrollView
MIT License
6.05k stars 633 forks source link

Container navigation controller breaks bar #396

Open markst opened 4 years ago

markst commented 4 years ago

Seems that if I use a navigation controller as a child view controller, the scroll does not appear to work as expected:

Screen Capture on 2020-08-14 at 09-40-06-2

CHECKOUT OPTIONS:
  AMScrollingNavbar:
    :commit: 37743f772b6a5e1328285d295b38cc400ff82d1e
    :git: https://github.com/andreamazz/AMScrollingNavbar.git
markst commented 4 years ago

The statusBarHeight could be the culprit here. If I replace the height with:

var statusBarHeight: CGFloat { return 0.0 }

The bar does behave how we like, however returning with the bar visible seems to break again:

markst commented 4 years ago

Actually it seems that navigationController resolves to nil upon viewDidDisappear which results in stopFollowingScrollView() not completing. Not sure if this is a iOS 13 change or fact I'm using contained navigation controller. Also wonder if scrollableView should be a weak reference.

So a fix to second issue is to stop following on willDisappear:

override func viewWillDisappear(_ animated: Bool) {
  super.viewWillDisappear(animated)

  if let navigationController = navigationController as? ScrollingNavigationController {
    navigationController.showNavbar(animated: true)
    navigationController.stopFollowingScrollView()
  }
}
andreamazz commented 4 years ago

Hi @markst Thanks for the detective work. I reckon that the issues are related to the contained navigation, it's something that I never considered while building the lib, so I expect issues.