Swift 在iOS 11中向UINavigationBar添加项目后面的子视图

Swift 在iOS 11中向UINavigationBar添加项目后面的子视图,swift,xcode,uinavigationbar,ios11,Swift,Xcode,Uinavigationbar,Ios11,在我的UINavigationBar子类中,我添加了一个带有insertSubview(customView,at:0)的子视图,以便将其放置在UINavigationBar的“后面” //containerView containerView.frame = CGRect(x: 0, y: -(statusBarHeight), width: UIScreen.main.bounds.width, height: frame.height + statusBarHeight) containe

在我的
UINavigationBar
子类中,我添加了一个带有
insertSubview(customView,at:0)
的子视图,以便将其放置在
UINavigationBar
的“后面”

//containerView
containerView.frame = CGRect(x: 0, y: -(statusBarHeight), width: UIScreen.main.bounds.width, height: frame.height + statusBarHeight)
containerView.clipsToBounds = true

insertSubview(containerView, at: 0)
在iOS 10中,添加的子视图将根据我的需要添加标题和
uibarbuttonims
,但在iOS 11中,苹果似乎改变了一些东西,因为无论我尝试什么
customView
,每次都会放在
UINavigationBar
的前面

//containerView
containerView.frame = CGRect(x: 0, y: -(statusBarHeight), width: UIScreen.main.bounds.width, height: frame.height + statusBarHeight)
containerView.clipsToBounds = true

insertSubview(containerView, at: 0)
我已经试过改变索引了


你知道我该怎么解决这个问题吗

你可以看看这个。我是这样解决的:

override func layoutSubviews() {  
        super.layoutSubviews()  
        for aView in self.subviews {  
            if NSStringFromClass(type(of: aView)) == "_UINavigationBarContentView" {  
                aView.frame = CGRect(x: 0, y: 20, width: aView.frame.width, height: aView.frame.height)  
            }  
            else if NSStringFromClass(type(of: aView)) == "_UIBarBackground" {  
                aView.frame = CGRect(x: 0, y: 0, width: aView.frame.width, height: self.frame.height)  
            }  
        }  
    }  

我添加了与iOS 11 beta 9相同问题的代码请提取解决方案并将其作为答案发布。不要简单地链接到其他网站