Uinavigationbar iPhoneX上导航栏的渐变背景

Uinavigationbar iPhoneX上导航栏的渐变背景,uinavigationbar,swift4,ios11,background-color,iphone-x,Uinavigationbar,Swift4,Ios11,Background Color,Iphone X,iPhoneX上的导航栏不使用渐变背景。 这是我的功能代码: func setGradientBackground(Colors: [UIColor]) { var updatedFrame = bounds updatedFrame.size.height += self.frame.origin.y if UIDevice().userInterfaceIdiom == .phone { if UIScreen.main.nativeBou

iPhoneX上的导航栏不使用渐变背景。 这是我的功能代码:

    func setGradientBackground(Colors: [UIColor]) {

    var updatedFrame = bounds
    updatedFrame.size.height += self.frame.origin.y

    if UIDevice().userInterfaceIdiom == .phone {
        if UIScreen.main.nativeBounds.height == 2436{
            updatedFrame.size.height += 44
        } else {
            updatedFrame.size.height += 20
        }

    }

    let gradientLayer = CAGradientLayer(frame: updatedFrame, colors: Colors)
    setBackgroundImage(gradientLayer.createGradientImage(), for: UIBarMetrics.default)

}

谢谢,但这适用于除iPhone以外的所有其他设备。那是我的问题!使用
updatedFrame.size.height+=navigationBar.frame.maxY
告诉我