ios - 隐藏标签栏时白色状态栏

标签 ios swift uitabbarcontroller

我有一个自定义的 UITabBarController,很久以前我发现这段代码可以在我按下某个按钮时动画隐藏标签栏。在升级到 iOS 11 之前,这一直很好用,现在当隐藏标签栏时状态栏变为白色。

我不明白发生了什么事。好像Y的view位置增加了20点,在状态栏下方,代码:

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()
        }
    }

}

最佳答案

我在我的 iPhone 6s Plus 上发现了同样的问题。我最初运行的是 iOS 11.0.2,它似乎工作正常。更新到 iOS 11.1.2 后出现问题。这让我相信它是在 11.1 之后引入的。

解决方案:删除这一行似乎给我带来了预期的结果。

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

希望对你有帮助

- 阿米尔

关于ios - 隐藏标签栏时白色状态栏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47136336/

相关文章:

ios - 如何在 iOS 中正确组合 Tab Bar View 和 Navigation Bar

iphone - 如何在不使用标签栏的情况下在 ViewController 之间切换?

android - CodenameOne 的 iOS 构建失败

string - 获取有关 Swift 中搜索栏的信息

ios - 使用 Grand Central Dispatch 安排每天同一时间的功能

swift 3 : Be able to tap view behind a collectionViewCell?

iPhone:如何在 Tabbar 应用程序中的多个 View Controller 之间传递数据

android - ejabberd 如何在 xmppframework 中使用 MUC/SUB

每次点击应用程序图标时,iOS 13 应用程序都会请求一个新场景

iOS 应用因未捕获的 NSException 而终止