[ad_1]
I’ve two buttons: one for taking picture and one for selecting it from the picture library. They each name UIImagePickerDelegate. The issue is that UIImagePickerDelegate will get known as after selecting picture from the library, however it does not get known as after taking an image. So once I take an image and press “Use”, I get again to my view, however nothing occurs. Right here is my code:
open class BackgroundImageViewController: UIViewController, BackgroundViewController, UINavigationControllerDelegate {
var imagePicker = UIImagePickerController()
@IBAction func didTapTakePhoto(_ sender: UIButton) {
imagePicker.sourceType = .digital camera
imagePicker.allowsEditing = true
imagePicker.delegate = self
self.current(imagePicker, animated: true, completion: nil)
// This half works effective, view for taking image is introduced, and I can take an image efficiently.
}
@IBAction func didTapChoosePhoto(_ sender: UIButton) {
imagePicker.sourceType = .photoLibrary
imagePicker.allowsEditing = true
imagePicker.delegate = self
self.current(imagePicker, animated: true, completion: nil)
}
}
extension BackgroundImageViewController: UIImagePickerControllerDelegate {
public func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo information: [UIImagePickerController.InfoKey : Any]) {
// This technique is getting known as solely once I select the picture from the library, not once I take the image.
let picture = information[UIImagePickerController.InfoKey.originalImage] as! UIImage
imageView.picture = picture
picker.dismiss(animated: true, completion: nil)
}
public func imagePickerControllerDidCancel(_ picker: UIImagePickerController) {
picker.dismiss(animated: true, completion: nil)
}
}
This drawback is driving me mad, as a result of code for 2 buttons is nearly similar. For positive, I’ve all obligatory permissions set in my information.plist file:
Any assistance is appreciated!
[ad_2]

