Ashish
Ashish

Reputation: 1897

ios 11 navigation bar overlap status bar

In ios 11 navigation bar is overlapping status bar. If any body faced the same issue kindly help.

enter image description here

Upvotes: 9

Views: 9482

Answers (3)

Ucdemir
Ucdemir

Reputation: 3098

Set child view to top constraint of superview... Click for edit constraint If you see "Align Top to : Safe Area " change it to superview so that it will overlap

Upvotes: 0

Vitalii
Vitalii

Reputation: 4437

Had similar problem. In my case it turned out that previous view controller had custom nav bar and therefore it was hiding both - nav bar and status bar. There was

UIApplication.shared.setStatusBarHidden(true, with: UIStatusBarAnimation.none)
UIApplication.shared.setStatusBarStyle(.default, animated: false)

And in the problematic view controller I had this:

UIApplication.shared.setStatusBarStyle(.default, animated: false)
UIApplication.shared.setStatusBarHidden(false, with: UIStatusBarAnimation.none)

The issue was fixed simply by putting the two lines in the correct order:

UIApplication.shared.setStatusBarHidden(false, with: UIStatusBarAnimation.none)
UIApplication.shared.setStatusBarStyle(.default, animated: false)

All things above are deprecations, so another possible fix would probably be changing this to the recommended way of hiding status bar (which is not yet ideal as discussed here: setStatusBarHidden deprecated, but only thing that works).

Upvotes: 0

Darren Cheng
Darren Cheng

Reputation: 1435

Not sure if this is the same issue, but we ran into this as well when upgrading to iOS 11.

See ios 11 custom navbar goes under status bar

We were manually setting nav bar height to 64 and pinning to the superview edges. Conforming to the UINavigationBarDelegate protocol and implementing the UIBarPositioningDelegate delegate method solved it for us.

We replaced

navigationBar.autoPinEdgesToSuperviewEdgesExcludingEdge(.bottom)
navigationBar.autoSetDimension(.height, toSize: 64)

with

...
  if #available(iOS 11.0, *) {
    navigationBar.topAnchor.constraint(
      equalTo: self.view.safeAreaLayoutGuide.topAnchor
    ).isActive = true
  } else {
    navigationBar.topAnchor.constraint(
      equalTo: topLayoutGuide.bottomAnchor
    ).isActive = true
  }
  navigationBar.autoPinEdge(toSuperviewEdge: .left)
  navigationBar.autoPinEdge(toSuperviewEdge: .right)
  navigationBar.delegate = self
...

public func position(for bar: UIBarPositioning) -> UIBarPosition
  return .topAttached
}

This is using the purelayout DSL for some of the autolayout calls (https://github.com/PureLayout/PureLayout)

Credit goes to https://stackoverflow.com/users/341994/matt for the answer

Upvotes: 0

Related Questions