简体   繁体   中英

Navigationbar change (sometimes) position

I have problems with the position of my navigation bar.

Sometimes in random views on random phones my navigation bar hasn't the right position. It should be approximately 30-35 pixels lower.

The stupid thing is that I can't reproduce the bug. It seems that the bug is appearing when the phone have a lot of processes in the background.

The logic behind: My initial view is a Container View. This Container View implement a Navigation View Controller. I can't change this, because I undertook this project. If it does not have to be, I don't want to change the basic structure.

I know for you it is like a clairvoyant, because I can't give more information. I wish I could...

But maybe you know how to set the navigation in a fix position? Or you know this kind of bug and fixed it already? I am thankful for some ideas.

在此处输入图片说明

Update Thanks for reply.

I implement this code, I can't say, whether it's working, because my bug doesn't appear always. We will see and I will give reply as fast as possible.

 func fixPositionOfNavigationBar() {

    self.edgesForExtendedLayout = .Top
    self.extendedLayoutIncludesOpaqueBars = true

    if let navigationBar = self.navigationController?.navigationBar {
        positionForBar(navigationBar)
    }
}

When I know for what I am searching I found similar problems to mine.. maybe it helps: One possible solution Snd possible solution

Try conforming view controller to UIBarPositioningDelegate protocol by this:

func positionForBar(bar: UIBarPositioning) -> UIBarPosition  {
  return UIBarPosition.TopAttached
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM