访问相机时如何检查图像为零并按相机上的取消键
我已经过测试
第一步
我已经过测试
第二步
检查图像拍照==>可选(UIImagePickerController:0x10286ca00)
我想检查相机上的情况是否取消,然后按项目上的保存按钮返回
如何解决…这种情况 我的下面的代码
拍照
@IBAction func takePhotoReturnOfSealButton(_ sender: UIButton) {
imagePickerStoreListReturnSealLock = UIImagePickerController()
imagePickerStoreListReturnSealLock.delegate = self
imagePickerStoreListReturnSealLock.sourceType = .camera
present(imagePickerStoreListReturnSealLock,animated: true, completion: nil)
print("Check image take photo ==> \(String(describing: imagePickerStoreListReturnSealLock))")
}//takePhotoReturnOfSealButton
保存照片
@IBAction func saveImageToDevice(_ sender: UIButton) {
//Save photo to device not success have nil value
if(imagePickerStoreListReturnSealLock == nil){
showAlert(title: "No Have Photo", message: "Please take photo")
print("Check image cannot save ==> \(String(describing: imagePickerStoreListReturnSealLock))")
}else{
// Save photo to device success
UIImageWriteToSavedPhotosAlbum(showImageTakePhotoReturnOfSeal.image!, self, #selector(image(_:didFinishSavingWithError:contextInfo:)), nil)
print("Check image Save to device ==> \(String(describing: showImageTakePhotoReturnOfSeal))")
}
}//saveImageToDevice
答案 0 :(得分:0)
每当取消图像选择器时,就会调用一个委托方法-
func imagePickerControllerDidCancel(_ picker: UIImagePickerController) {
//Perform your action when cancel has been pressed
}
拾取图像后将调用此方法-
func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey : Any]) {
if picker == imagePicker {
//Save your image
imagePicker.dismiss(animated: true, completion: nil)
}
}
只需记住在上面进行定义-
var imagePicker = UIImagePickerController()
和在viewDidLoad
中imagePicker.delegate = self
答案 1 :(得分:0)
单击取消图像选择器时,将调用以下委托方法:
public func imagePickerControllerDidCancel(_ picker: UIImagePickerController) {
picker.dismiss(animated: true, completion: nil)
}
当您选择图像时,将调用以下委托方法:
func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey : Any]) {
let image : UIImage = info[UIImagePickerController.InfoKey.originalImage] as! UIImage
picker.dismiss(animated: true, completion: nil)
UIImageWriteToSavedPhotosAlbum(image!, nil, nil, nil)//to save image in saved photo album
}
希望这会有所帮助