Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
776 views
in Technique[技术] by (71.8m points)

ios - 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)

        })

    }
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...