我尝试自定义导航栏并使用垂直对齐方式将其设置得更大。这是我的代码:
@IBOutlet weak var topNavTitleLabel: UILabel!
@IBOutlet weak var topNavStackView: UIStackView!
@IBOutlet weak var leftNavHomeButton: UIBarButtonItem!
@IBOutlet weak var rightNavSearchButton: UIBarButtonItem!
var rightNavSearchButton_: UIBarButtonItem?
@IBAction func searchAction(sender: UIButton) {
topNavStackView.hidden = true
topNavStackView.hidden = false
rightNavSearchButton_ = rightNavSearchButton
navigationItem.rightBarButtonItem = nil
}
@IBAction func performSearch(sender: UIButton) {
topNavStackView.hidden = false
topNavStackView.hidden = true
navigationItem.rightBarButtonItem = rightNavSearchButton_
}
override func viewDidLoad() {
super.viewDidLoad()
}
override func viewDidAppear(animated: Bool) {
super.viewDidAppear(animated)
if let navConBar = self.navigationController?.navigationBar {
navConBar.bounds = CGRectMake(0, 0, view.bounds.width, 100)
navConBar.setTitleVerticalPositionAdjustment(-10.0, forBarMetrics: .Default)
let offset = UIOffset(horizontal: 0, vertical: -10)
navigationItem.rightBarButtonItem?.setTitlePositionAdjustment(offset, forBarMetrics: .Default)
navigationItem.leftBarButtonItem?.setTitlePositionAdjustment(offset, forBarMetrics: .Default)
}
}
当它出现时看起来不错。
但是当我点击右侧导航栏按钮时,左按钮会变为向下。
当它回头时:
如何解决?