【发布时间】:2017-12-24 09:17:31
【问题描述】:
我希望能够在我的应用程序中拍照。但是,当我按下按钮时,屏幕变黑。你能帮我解决这个问题吗? 我有 imageView 和一个按钮来制作照片。
我有这样的代码:
var imagePicker: UIImagePickerController!
@IBOutlet var imageView: UIImageView!
@IBAction func takePhoto(_ sender: UIButton) {
let imagePicker = UIImagePickerController()
imagePicker.delegate = self
imagePicker.sourceType = UIImagePickerControllerSourceType.camera
imagePicker.allowsEditing = false
let vc = ViewController()
var navigationController = UINavigationController(rootViewController: vc)
self.present(navigationController, animated: true, completion: nil)
}
添加了类中所有必要的委托。 self.present() 中可能存在错误,但在其他情况下它不起作用。
self.presentViewController(imagePicker, animated: true, completion: nil) 在新版本中不起作用。
第二个问题: 是否可以直接在视图中看到相机屏幕?不只是在按下按钮之后?
【问题讨论】:
标签: ios swift xcode view photo