我正在创建一个应用程序,我打开相机作为第一件事。我能够做到这一点。一旦用户拍摄了照片,他就会看到两个选项,“使用照片”或“取消”。我的问题是,我如何在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")
}发布于 2017-03-30 05:17:19
我的问题是,我如何在swift 3中编写代码,以便将“使用照片”按钮设置为我的方便,比如将照片存储到图库,或者其他一些操作。
您已经将ViewController设置为图像拾取器控制器的委托,因此只需在ViewController中实现imagePickerController(_:didFinishPickingMediaWithInfo:)方法。
https://stackoverflow.com/questions/43104243
复制相似问题