在我的UINavigationBar
子类中,我添加了一个带有insertSubview(customView, at: 0)
的子视图,以便将其放在UINavigationBar
的“后面”。
在iOS 10中,添加的子视图将添加标题和UIBarButtonItems
,因为我想要它,但在iOS 11中,似乎Apple改变了一些东西,因为无论我尝试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)
我已经尝试过更改索引了。
知道我应该如何解决这个问题吗?
答案 0 :(得分:1)
你可以看看这个。我这样解决了:
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)
}
}
}