【问题标题】:How to update the toolbar for Swift5 + Xcode11.6?如何更新 Swift 5 + Xcode 11.6 的工具栏?
【发布时间】:2020-07-28 12:02:47
【问题描述】:

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

有 2 种输入:以编程方式和情节提要。他们都没有出现。 以编程方式(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 启动过程中的屏幕截图:

【问题讨论】:

    标签: swift toolbar swift5 xcode11


    【解决方案1】:

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

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

    问题是 - 根 UINavigationController。 以前在 Apple 添加 SceneDelegate 之前它很好,因为我必须将 UINavigationController 设置为情节提要的初始视图。就是这样。现在我们可以工作了。

    现在,我们有了 SceneDelegate(我已经删除了这个文件)。 AppDelegate 现在应该引用这个导航控制器(确保它在故事板上有标识符,就像我们为视图控制器做的那样)。 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
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-11-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-12-19
      • 1970-01-01
      • 1970-01-01
      • 2017-07-21
      相关资源
      最近更新 更多