swift - 如何更新 Swift5 + Xcode11.6 的工具栏?
问题描述
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 启动时的截图:
解决方案
这个解决方案Swift3对我有用:
let newViewController = NewViewController()
self.navigationController?.pushViewController(newViewController, animated: true)
问题是 - 根UINavigationController
。以前在 Apple 添加 SceneDelegate 之前它很好,因为我必须将 设置UINavigationController
为 Storyboard 的初始视图。就是这样。现在我们可以工作了。
现在,我们有了 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
}
推荐阅读
- java - 将 Springboot 应用程序制作成 maven 插件
- javascript - 根据 Firestore 中的开始日期和结束日期查询创建的字段,即时间戳
- excel - 从其他工作表中添加形状中的文本
- git - 主分支无法使用 Git 从远程拉取
- android - 应用程序图标在 OS 9 设备上不支持
- mysql - 如何使用 GROUPBY mysql 查询优化 COUNT?
- python-3.x - 列表到元组列表RGB python
- mysql - 如何将一个表与一对多表组合成一个记录结果
- python - Django 应用程序和 Python 包依赖项
- android - BLE 制造商广告数据