我在iOS 13及其新的工作表样式演示中遇到了这个奇怪的问题。
在ViewController1中,我以模态形式呈现了嵌入到NavigationController中的ViewController2,并且一切正常。
然后从ViewController2模态化呈现嵌入到NavigationController中的ViewController3,然后得到Right Bar Button偏移量。
这是问题的视频:有人修复了吗?
主视图控制器
import UIKit
let vc1identifier = "vc1identifier"
let vc2identifier = "vc2identifier"
class ViewController: UIViewController {
@IBAction func tap1(_ sender: UIButton) {
if let navigation = self.storyboard?.instantiateViewController(withIdentifier: vc1identifier) as? UINavigationController,
let nextVC = navigation.contentViewController as? UnoViewController {
//self.navigationController?.pushViewController(nextVC, animated: true)
self.present(navigation, animated: true, completion: nil)
}
}
}
extension UIViewController {
var contentViewController: UIViewController {
if let navcon = self as? UINavigationController {
return navcon.visibleViewController!
} else {
return self
}
}
}
第二个视图控制器
import UIKit
class UnoViewController: UIViewController {
@IBOutlet weak var barButton: UIBarButtonItem!
override func viewDidLayoutSubviews() {
super.viewDidLayoutSubviews()
barButton.title = "GotoVC2"
}
@IBAction func pressThis(_ sender: UIBarButtonItem) {
if let navigation = self.storyboard?.instantiateViewController(withIdentifier: vc2identifier) as? UINavigationController,
let nextVC = navigation.contentViewController as? DueViewController {
self.present(navigation, animated: true, completion: nil)
}
}
}
答案 0 :(得分:1)
我遇到了同样的问题。
解决方案很容易,您只需要告诉导航栏它需要这样的布局
override public func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
if #available(iOS 13.0, *) {
navigationController?.navigationBar.setNeedsLayout()
}
}