如何更新 Swift5 + Xcode11.6 的工具栏?

How to update the toolbar for Swift5 + Xcode11.6?

Swift3 应用程序之前(1-2 年前)运行良好。 现在它停止显示底部的工具栏按钮。

有 2 种输入:编程方式和故事板方式。 None 出现了。 以编程方式(VideoViewController):

override func viewDidLoad()
{
    super.viewDidLoad()
    
    // nabigationBar customization
    self.navigationController?.isToolbarHidden = false
    //self.navigationController?.setToolbarHidden(false, animated: true)
    var items = [UIBarButtonItem]()
    items.append( UIBarButtonItem(barButtonSystemItem: .flexibleSpace, target: self, action: nil) )
    items.append( UIBarButtonItem(barButtonSystemItem: .camera, target: self, action: #selector(buttonCapture(_:))) )
    items.append( UIBarButtonItem(barButtonSystemItem: .flexibleSpace, target: self, action: nil) )
    self.toolbarItems = items
    
    //captureSession to capture the current image
    captureSession.sessionPreset = .photo
    guard let captureDevice = AVCaptureDevice.default(.builtInWideAngleCamera, for: AVMediaType.video, position: .front) else { return }
    guard let input = try? AVCaptureDeviceInput(device: captureDevice) else { return }
    captureSession.addInput(input)
    captureSession.startRunning()
    
    let previewLayer = AVCaptureVideoPreviewLayer(session: captureSession)
    view.layer.addSublayer(previewLayer)
    previewLayer.frame = view.frame
    
    let dataOutput = AVCaptureVideoDataOutput()
    dataOutput.setSampleBufferDelegate(self, queue: DispatchQueue(label: "videoQueue"))
    captureSession.addOutput(dataOutput)
    setupIdentifierConfidenceLabel()
}

有一个导航控制器(初始视图)。 VideoViewController 被之前的 VC:

调用
let storyBoard: UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
let videoVC = storyBoard.instantiateViewController(withIdentifier: "VideoViewController") as UIViewController
self.present(videoVC, animated: true, completion: nil)

此 VC 当前状态的屏幕截图:

VideoViewController 启动期间的屏幕截图:

这个解决方案 Swift3 对我有用:

let newViewController = NewViewController()
self.navigationController?.pushViewController(newViewController, animated: true)

问题是 - root UINavigationController。 以前在 Apple 添加 SceneDelegate 之前它很好,因为我必须将 UINavigationController 设置为 Storyboard 的初始视图。而已。现在我们可以工作了。

现在,我们有了 SceneDelegate(我已经删除了这个文件)。 AppDelegate 现在应该引用这个 Navigation Controller(确保它在故事板中有标识符,就像我们为 View Controller 做的那样)。 AppDelegate 文件现在应该使用 Navigation Controller:

var window: UIWindow?

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
    // Override point for customization after application launch.
    
    let mainStoryboard : UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
    let initialViewController : UIViewController = mainStoryboard.instantiateViewController(withIdentifier: "navigator") as! UINavigationController
    
    self.window = UIWindow(frame: UIScreen.main.bounds)
    self.window?.rootViewController = initialViewController
    self.window?.makeKeyAndVisible()
    
    return true
}