1

I have a custom UITabBarController and I found this code a long time ago to animated hide tab bar when I press some button. This works very well until upgrade to iOS 11 and now the status bar turns white when tab bar is hidden.

I can't figure out what happened. It's like Y position of view increase 20 points, below the status bar and code:

enter image description here

extension CustomTabBarController {

    func showTabBar(_ notification: Foundation.Notification) {
        setTabBarVisible(true, animated: true)
    }

    func hideTabBar(_ notification: Foundation.Notification) {
        setTabBarVisible(false, animated: true)
    }

    fileprivate func setTabBarVisible(_ visible: Bool, animated: Bool) {
        let frame = tabBar.frame
        let height = frame.size.height
        let offsetY = (visible ? -height : height)
        let duration: TimeInterval = (animated ? 0.3 : 0.0)

        UIView.animate(withDuration: duration) {
            self.tabBar.frame = frame.offsetBy(dx: 0, dy: offsetY)
            self.view.frame = CGRect(x: 0.0, y: 0.0, width: self.view.frame.width, height: self.view.frame.height + offsetY)
            self.view.setNeedsDisplay()
            self.view.layoutIfNeeded()
        }
    }

}
Paulo Rodrigues
  • 5,273
  • 7
  • 35
  • 58

1 Answers1

1

I noticed the same issue on my iPhone 6s Plus. I originally was running iOS 11.0.2 and it seemed to work properly. After updating to iOS 11.1.2, it has the issue. This leads me to believe it was introduced after 11.1.

Solution: Removing this line seemed to give me the results that I expected.

self.view.frame = CGRect(x: 0.0, y: 0.0, width: self.view.frame.width, height: self.view.frame.height + offsetY)

Hope this helps

- Amir

  • Found this as well. Not sure if you've figured it out or not but might be helpful to others. https://stackoverflow.com/questions/44492404/safe-area-of-xcode-9/45334411#45334411 – Amir Nazari Dec 04 '17 at 19:34