在iOS 11中由于状态栏视图下降了20像素,但在iOS 10中运行良好,[iOS 11中的状态栏比iOS 10中的常规栏高20倍
用于生成自定义导航栏
在类Base中它是函数之一,将此类继承到我的视图控制器并且只是编译。
在iOS 10中,它按预期显示,但在iOS 11中没有显示
func setUpNavBar() {
self.navigationController?.navigationBar.isHidden = true;
navBar?.translatesAutoresizingMaskIntoConstraints = false
navBar?.lblTitle.text = self.title
navBar?.ViewController = self
navBar?.btnmenu.addTarget(self, action: #selector(menuTapped), for: .touchUpInside)
navBar?.btnHome.addTarget(self, action: #selector(homeTapped), for: .touchUpInside)
self.view.addSubview(navBar!)
let views = [ "navView": navBar]
let horizontal = NSLayoutConstraint.constraints(withVisualFormat: "H:|-0-[navView]-0-|", options: NSLayoutFormatOptions(), metrics: nil, views: views)
let vertical = NSLayoutConstraint.constraints(withVisualFormat: "V:|-[navView(64)]", options: NSLayoutFormatOptions(), metrics: nil, views: views)
navBar?.internalview.contentMode = .scaleAspectFit
view.addConstraints(horizontal)
view.addConstraints(vertical)
}
答案 0 :(得分:0)
我假设您的'64'值来自标准状态栏的高度(20)+导航栏的高度(44)。
这在iOS 10上运行正常,因为视图会在y = 0处添加。在iOS 11上,由于新的“安全区域布局”,视图可能无法添加到零,这可能会导致y = 20。 / p>
我相信你的情况你必须做以下事情:
if #available(iOS 11.0, *) {
let vertical = NSLayoutConstraint.constraints(withVisualFormat: "V:|-[navView(44)]", options: NSLayoutFormatOptions(), metrics: nil, views: views)
}
else {
let vertical = NSLayoutConstraint.constraints(withVisualFormat: "V:|-[navView(64)]", options: NSLayoutFormatOptions(), metrics: nil,
}