10

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

enter image description here

Ashish
  • 1,899
  • 20
  • 22
  • It's an xcode9 bug.. everything you've done is fine we're all facing the same issues. I'm currently downloading xcode8.3.3 and will work from there until they release a fix – Faisal Sep 22 '17 at 17:36
  • @Faisal It'd be helpful if you post the bug link here. – Sravan Sep 24 '17 at 20:12
  • 1
    @Sravan https://stackoverflow.com/questions/46138245/how-to-change-navigationbar-height-in-ios-11/46138389?noredirect=1#comment79643281_46138389 you can see people discussing the same issue here and identifying the bug – Faisal Sep 25 '17 at 10:37
  • @Sravan thanks for the link and the answer, I was thinking that this issue is because of the newly introduced safe area in ios11 – Ashish Sep 25 '17 at 11:01
  • 2
    Possible duplicate of [How to change navigationBar height in iOS 11?](https://stackoverflow.com/questions/46138245/how-to-change-navigationbar-height-in-ios-11) – D. Greg Oct 16 '17 at 01:15
  • 1
    @D.Greg the quest doesn't seem to be duplicate. The "How to change..." answer is about adding a custom nav bar, while I'm see this problem with a normal "out-of-box" nav bar at the moment. – Vitalii Nov 21 '17 at 13:21
  • @Ashish were you able to solve this issue ? – user427969 Oct 02 '20 at 05:03

3 Answers3

0

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

Darren Cheng
  • 1,435
  • 14
  • 12
  • Here when we tried to change the safrealayoutguide we are getting crash as below reason: 'Unable to activate constraint with anchors and because they have no common ancestor. Does the constraint or its anchors reference items in different view hierarchies? That's illegal.' – dineshprasanna Jun 24 '18 at 08:26
0

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).

Vitalii
  • 4,267
  • 1
  • 40
  • 45
0

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

Ucdemir
  • 2,852
  • 2
  • 26
  • 44