该应用程序可以与任何其他设备完美配合,但是iPhone 4s可以做到这一点。我使用了屏幕调试器,可以看到它的y位置增加了,但我不知道为什么。
这是代码段,我从configureNavigationBarWithTitle()
方法调用viewDidLoad()
。
func configureNavigationBarWithTitle(title: String, shouldDisplayHomeButton: Bool = false) {
self.navigationController?.setNavigationBarHidden(false, animated: true)
self.navigationItem.titleView = UIView.createNavigationTitleView(title: title)
self.navigationItem.leftBarButtonItem = UIBarButtonItem.createAZBackButton(target: self)
self.navigationItem.leftBarButtonItem?.action = #selector(navigateBack(sender:))
if shouldDisplayHomeButton {
self.navigationItem.rightBarButtonItem = UIBarButtonItem.createAZHomeButton(target: self)
self.navigationItem.rightBarButtonItem?.action = #selector(navigateToRoot(sender:))
}
}
extension UIBarButtonItem {
static func createAZBackButton(target: Any?) -> UIBarButtonItem {
let img = UIImage(named: "back")
let button = UIBarButtonItem(image: img, style: .plain, target: target, action: nil)
button.title = ""
button.tintColor = UIColor.white
button.setBackgroundVerticalPositionAdjustment(0, for: .default)
return button
}
static func createAZHomeButton(target: Any?) -> UIBarButtonItem {
let img = UIImage(named: "home")
let button = UIBarButtonItem(image: img, style: .plain, target: target, action: nil)
button.title = ""
button.tintColor = UIColor.white
button.setBackgroundVerticalPositionAdjustment(0, for: .default)
return button
}