iosswiftuiimageviewuiimagepickercontroller

Add a circular cropping component for UIImagePicker?


I Have a circular framed UIImageView and I need to add a circular framed cropping tool for the UIImagePickerController, after the image is selected from a photo library. Very similar to Instagram's UIImagePicker's crop component. How do I add this type of component?

UPDATE

I've found this repo with a circular cropping tool https://github.com/ruslanskorb/RSKImageCropper

but can someone guide me on to how to implement this cropping tool with the UIImagePickerController after the user selects a photo from the photo library?

UPDATE

I am getting the following message in my debugger :

enter image description here

and the buttons in my crop view are disabled, meaning I cannot select them.. what message is the debugger relaying on to me?

here is my code:

  @IBAction func chooseProfilePicture(sender: AnyObject) {

        var myPickerController = UIImagePickerController()
        myPickerController = UIImagePickerController()
        myPickerController.delegate = self;
        myPickerController.sourceType = UIImagePickerControllerSourceType.PhotoLibrary

        self.presentViewController(myPickerController, animated: true, completion: nil)
    }

    func imagePickerController(picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [NSObject : AnyObject]) {

        var image : UIImage = (info[UIImagePickerControllerOriginalImage] as? UIImage)!

        editProfilePictureImageView.image = image

        self.dismissViewControllerAnimated(false, completion: { () -> Void in

            var imageCropVC : RSKImageCropViewController!

            imageCropVC = RSKImageCropViewController(image: image, cropMode: RSKImageCropMode.Circle)

            imageCropVC.delegate = self

            self.navigationController?.pushViewController(imageCropVC, animated: true)

        })

    }

Solution

  • Example Demo

    Yes you can add RSKImageCropper in your UIImagePickerController

    define imagePicker

    var imagePicker : UIImagePickerController!
    

    in ViewDidLoad

        imagePicker = UIImagePickerController()
        imagePicker.delegate = self
        imagePicker.sourceType = UIImagePickerControllerSourceType.PhotoLibrary;
        self.presentViewController(imagePicker, animated: true, completion: nil)
    

    Delegate methode :

    func imagePickerController(picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [NSObject : AnyObject])
    {
    
        var image : UIImage = (info[UIImagePickerControllerOriginalImage] as? UIImage)!
    
        picker.dismissViewControllerAnimated(false, completion: { () -> Void in
    
            var imageCropVC : RSKImageCropViewController!
    
            imageCropVC = RSKImageCropViewController(image: image, cropMode: RSKImageCropMode.Circle)
    
            imageCropVC.delegate =self
    
            self.navigationController?.pushViewController(imageCropVC, animated: true)
    
        })
    
    }
    

    see :

    enter image description here