我正在创建一个应用程序,我首先打开相机。我能够做到这一点。用户拍摄照片后,会显示两个选项,'使用照片'或者'取消'。我的问题是如何在swift 3中编写代码来设置“使用照片”。按钮,方便我将照片存储到图库或其他一些操作。请建议一些代码来做到这一点。谢谢!
以下是我用来打开相机的代码:
class ViewController: UIViewController, UINavigationControllerDelegate, UIImagePickerControllerDelegate {
override func viewDidAppear(_ animated: Bool) {
if UIImagePickerController.isSourceTypeAvailable(UIImagePickerControllerSourceType.camera) {
let image = UIImagePickerController()
image.delegate = self
image.sourceType = UIImagePickerControllerSourceType.camera
image.allowsEditing = false
self.present(image, animated: true)
} else {
print("This device does not support camera")
}
}
}
func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) {
if let image = info[UIImagePickerControllerOriginalImage] as? UIImage {
myImageView.image = image
}
else {
//Error message
}
self.dismiss(animated: true, completion: nil)
print("camera is dismissed or not")
}
答案 0 :(得分:0)
我的问题是如何在swift 3中编写代码来设置“使用照片”。按钮,方便我将照片存储到图库或其他一些操作。
您已将ViewController
设置为图片选择控制器的委托,因此您只需在ViewController
中实施imagePickerController(_:didFinishPickingMediaWithInfo:)
方法。