import UIKit
class DrawingTransistionViewController: UIViewController,
UIImagePickerControllerDelegate,
UINavigationControllerDelegate
{
override func viewWillAppear(_ animated: Bool)
{
let imagePicker = UIImagePickerController()
imagePicker.delegate = self
imagePicker.sourceType = .camera
self.present(imagePicker, animated: true, completion: nil)
}
}
当前,当代码运行时,它会打开相机,但当您退出相机时,相机会再次打开,因为 View 再次出现。所以我陷入了一个不断的循环。我希望相机在 View 之间转换时仅打开一次。我已经尝试过 viewWillDisappear()、viewDidAppear 和 viewDidDisappear() 但没有取得任何成功。
这是我能找到的唯一有用的文档,但我没有找到太多运气。 https://developer.apple.com/reference/uikit/uiviewcontroller#//apple_ref/doc/uid/TP40006926-CH3-SW18
有什么想法吗?
谢谢
最佳答案
我没有完全理解你的问题。 Uglu 解决方案是只放置 boolen isCameraOpen ,然后在打开相机之前将 aks 打开,第一次打开时只需将该 bool 设置为 true 。为什么不使用 viewDidLoad?
关于ios - iOS 中 View 转换时相机打开,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41111616/