自定义一个类BMNavigationBar继承UINavigationBar,重写layoutSubviews方法(记得初始化的地方改成自定义的BMNavigationBar)
override func layoutSubviews() {
super.layoutSubviews()
if #available(iOS11.0, *) {
for view in self.subviews{
if(view.isKind(of:NSClassFromString("_UIBarBackground")!)) {
view.frame=self.bounds
}else if(view.isKind(of:NSClassFromString("_UINavigationBarContentView")!)){
var frame= view.frame
frame.origin.y=20
view.frame= frame
}}}}