UIImagePickerController photo edit area

33 Views Asked by At

It seems like I can't edit a certain area(mostly top/bottom part) if I use the sourceType == .camera.

let picker = UIImagePickerController()
picker.sourceType = .camera
picker.delegate = self
picker.allowsEditing = true
present(picker, animated: true)

With the code above, after I take a picture, it goes to the edit screen. I can zoom and move the picture to crop, but I can't really move to the top/bottom edge of the picture.

Tested on iOS 16.3.1 on iPhone13 mini/Pro Max. Is it a know issue or I missed something?

1

There are 1 best solutions below

2
Naqash Ali Gill On

class ViewController: UIViewController, UIImagePickerControllerDelegate, UINavigationControllerDelegate {

@IBOutlet weak var imageView: UIImageView!

func choosePhoto() {
    let picker = UIImagePickerController()
    picker.delegate = self
    picker.allowsEditing = true
    picker.sourceType = .photoLibrary
    present(picker, animated: true, completion: nil)
}

func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey : Any]) {
    if let editedImage = info[.editedImage] as? UIImage {
        imageView.image = editedImage
    } else if let originalImage = info[.originalImage] as? UIImage {
        imageView.image = originalImage
    }
    dismiss(animated: true, completion: nil)
}

func imagePickerControllerDidCancel(_ picker: UIImagePickerController) {
    dismiss(animated: true, completion: nil)
}

}