0
我正在創建一個應用程序,首先打開相機。我能夠做到這一點。用戶拍攝照片後,會顯示兩個選項,「使用照片」或「取消」。我的問題是,如何在swift 3中編寫代碼以設置「使用照片」按鈕,以方便我將照片存儲到圖庫或其他一些操作。請建議一些代碼來做到這一點。謝謝!快速設置不同動作的照相機按鈕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")
}
我實現了這個方法,但是即使我已經解僱了它,我的相機也不會點擊'使用照片'按鈕。我用新代碼更新了我的帖子。 –