andreamazz / AMScrollingNavbar

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

[strong issue] (only iPad, iPhone XS etc.) - Offset when uiviewcontroller is working with "presentViewController". #336

Closed StefaniOSApps closed 5 years ago

StefaniOSApps commented 5 years ago

Describe the bug There are problems if a UIViewController is not represented by "push" but by "present". Then there is an erroneous calculation of the UINavigationBar position. This creates a strong offset. The relative position of the UIViewcontollers.view must be taken into account in the position of the device window.

To Reproduce Steps to reproduce the behavior: See screenshot animation

  1. Run Demo on iPad,
  2. press on "table",
  3. scroll down and up .. see offset at the top.

Expected behavior No offset. A correct calculation of the uinavigationbar.

Screenshots https://imgur.com/a/YTxh8dx

Demo Project https://github.com/StefaniOSApps/Example Run Demo on iPad, press on "table", scroll down and up .. see offset at the top.

StefaniOSApps commented 5 years ago

I fix this bug @andreamazz

please replace:

var statusBarHeight: CGFloat {
    var statusBarHeight = UIApplication.shared.statusBarFrame.size.height
    if #available(iOS 11.0, *) {
      // Account for the notch when the status bar is hidden
      statusBarHeight = max(UIApplication.shared.statusBarFrame.size.height, UIApplication.shared.delegate?.window??.safeAreaInsets.top ?? 0)
    }
    return statusBarHeight - extendedStatusBarDifference
  }

with

var statusBarHeight: CGFloat {
    var statusBarHeight = UIApplication.shared.statusBarFrame.size.height
    if #available(iOS 11.0, *) {
      // Account for the notch when the status bar is hidden
      statusBarHeight = max(UIApplication.shared.statusBarFrame.size.height, UIApplication.shared.delegate?.window??.safeAreaInsets.top ?? 0)
    }
    return max(statusBarHeight - extendedStatusBarDifference, 0)
  }