在我的应用中,我通过自定义相机捕捉图像。因此,在拍摄图像时,我正在呈现控制器,因此它在中心显示相机并且看起来像捕捉图像。 这是它的代码
let layerVC = cameraLayerViewController(nibName: "cameraLayerViewController", bundle: nil)
layerVC.modalPresentationStyle = .custom
Global.appDelegate.window?.rootViewController?.presentedViewController?.present(layerVC, animated: false, completion: nil)
DispatchQueue.main.asyncAfter(deadline: .now() + 0.4, execute: {
layerVC.dismiss(animated: false, completion: nil)
}
但在更改相机模式时,我在同一个控制器上显示另一个控制器
if (UserDefaults.standard.value(forKey: Global.g_UserDefaultKey.isFrontCamera) as? Bool == true)
{
UserDefaults.standard.set(false, forKey: Global.g_UserDefaultKey.isFrontCamera)
let controller : CameraVC = CameraVC(nibName: "CameraVC", bundle: nil)
self.present(controller, animated: false, completion: nil)
}
else
{
UserDefaults.standard.set(true, forKey: Global.g_UserDefaultKey.isFrontCamera)
let controller : CameraVC = CameraVC(nibName: "CameraVC", bundle: nil)
self.present(controller, animated: false, completion: nil)
}
现在当我在这个控制器上时,我试图让任何控制器无效。
let layerVC = cameraLayerViewController(nibName: "cameraLayerViewController", bundle: nil)
layerVC.modalPresentationStyle = .custom
Global.appDelegate.window?.rootViewController?.presentedViewController?.present(layerVC, animated: false, completion: nil)
DispatchQueue.main.asyncAfter(deadline: .now() + 0.4, execute: {
layerVC.dismiss(animated: false, completion: nil)
}
所以让我知道如何在已经呈现的控制器上呈现控制器。
答案 0 :(得分:0)
从根目录呈现第一个视图控制器:
let root = UIApplication.shared.keyWindow!.rootViewController!
let firstPresented = FirstViewController()
firstPresented.transitioningDelegate = yourPresentationDelegate
firstPresented.modalPresentationStyle = .custom
root.present(firstPresented, animated: false, completion: nil)
要present
第二个视图控制器,因为它已经呈现,所以你不能再次present
来自根目录,所以你必须present
来自当前呈现的内容(self
let secondPresented = SecondViewController()
secondPresented.transitioningDelegate = yourPresentationDelegate
secondPresented.modalPresentationStyle = .custom
self.present(secondPresented, animated: false, completion: nil)
1}}):
ngModelGroup