美文网首页
Swift、解决iPhone X出现的push时tabBar上移

Swift、解决iPhone X出现的push时tabBar上移

作者: 路在脚下了 | 来源:发表于2017-11-06 15:53 被阅读27次

直接上代码吧

// 自定义tabBar,强制设置frame,不让它随着push而改变高度
class CustomTabBar: UITabBar {
    
    override var frame: CGRect {
        get {
            return super.frame
        }
        set {
            var tmp = newValue
            if let superview = self.superview, tmp.maxY != superview.frame.height {
                tmp.origin.y = superview.frame.height - tmp.height
            }
            super.frame = tmp
        }
    }
}

使用,在tabBarController中通过KVC替换tabBar.

setValue(CustomTabBar(), forKey: "tabBar")

相关文章

网友评论

      本文标题:Swift、解决iPhone X出现的push时tabBar上移

      本文链接:https://www.haomeiwen.com/subject/ahplmxtx.html