'I wanna control crop area in ImagePicker

After selecting the image from the gallery, I can crop it as a still frame to crop it. I don't want this. I want to be able to change the crop size. I want to be able to change the crop area like in the second gif. How can I do this without resorting to a 3rd party library ?

Image Picker Manager:

class ImagePickerManager: NSObject, UIImagePickerControllerDelegate, UINavigationControllerDelegate {
  
  var picker = UIImagePickerController();
  var alert = UIAlertController(title: "Fotoğraf Seç", message: nil, preferredStyle: .actionSheet)
  var viewController: UIViewController?
  var pickImageCallback : ((UIImage) -> ())?;
  
  override init(){
    super.init()
    let cameraAction = UIAlertAction(title: "Kamerayı Aç", style: .default){
      UIAlertAction in
      self.openCamera()
    }
    let galleryAction = UIAlertAction(title: "Galeriden Seç", style: .default){
      UIAlertAction in
      self.openGallery()
    }
    let cancelAction = UIAlertAction(title: "İptal", style: .cancel){
      UIAlertAction in
    }
    
    // Add the actions
    picker.allowsEditing = true
    picker.delegate = self
    alert.addAction(cameraAction)
    alert.addAction(galleryAction)
    alert.addAction(cancelAction)
  }
  
  func pickImage(_ viewController: UIViewController, _ callback: @escaping ((UIImage) -> ())) {
    pickImageCallback = callback;
    self.viewController = viewController;
    
    alert.popoverPresentationController?.sourceView = self.viewController!.view
    
    viewController.present(alert, animated: true, completion: nil)
  }
  func openCamera(){
    alert.dismiss(animated: true, completion: nil)
    if(UIImagePickerController .isSourceTypeAvailable(.camera)){
      picker.sourceType = .camera
      self.viewController!.present(picker, animated: true, completion: nil)
    } else {
      let alertController: UIAlertController = {
        let controller = UIAlertController(title: "Warning", message: "You don't have camera", preferredStyle: .alert)
        let action = UIAlertAction(title: "OK", style: .default)
        controller.addAction(action)
        return controller
      }()
      viewController?.present(alertController, animated: true)
    }
  }
  func openGallery(){
    alert.dismiss(animated: true, completion: nil)
    picker.sourceType = .photoLibrary
    self.viewController!.present(picker, animated: true, completion: nil)
  }
  
  func imagePickerControllerDidCancel(_ picker: UIImagePickerController) {
    picker.dismiss(animated: true, completion: nil)
  }
  
  func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey : Any]) {
    
    if let image = info[.editedImage] as? UIImage {
      pickImageCallback?(image)
    } else if let image = info[.originalImage] as? UIImage {
      pickImageCallback?(image)
    }
    picker.dismiss(animated: true, completion: nil)
  }
  
  @objc func imagePickerController(_ picker: UIImagePickerController, pickedImage: UIImage?) {
    
  }
}

My code result:

enter image description here

I want do this:

enter image description here



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source