为 UIImagePicker 添加圆形裁剪组件?

Add a circular cropping component for UIImagePicker?(为 UIImagePicker 添加圆形裁剪组件?)

本文介绍了为 UIImagePicker 添加圆形裁剪组件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个圆形框架 UIImageView,我需要在从照片库中选择图像后,为 UIImagePickerController 添加一个圆形框架裁剪工具.非常类似于 Instagram 的 UIImagePicker 的 裁剪组件.如何添加这种类型的组件?

更新

我发现这个 repo 带有一个圆形裁剪工具

我的裁剪视图中的按钮被禁用,这意味着我无法选择它们.调试器向我传递什么消息?

这是我的代码:

 @IBAction func chooseProfilePicture(sender: AnyObject) {var myPickerController = UIImagePickerController()myPickerController = UIImagePickerController()myPickerController.delegate = self;myPickerController.sourceType = UIImagePickerControllerSourceType.PhotoLibraryself.presentViewController(myPickerController,动画:真,完成:无)}func imagePickerController(picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [NSObject: AnyObject]) {var image : UIImage = (info[UIImagePickerControllerOriginalImage] as?UIImage)!editProfilePictureImageView.image = 图像self.dismissViewControllerAnimated(false, completion: { () -> Void invar imageCropVC : RSKImageCropViewController!imageCropVC = RSKImageCropViewController(图像:图像,cropMode:RSKImageCropMode.Circle)imageCropVC.delegate = selfself.navigationController?.pushViewController(imageCropVC, 动画: true)})}

解决方案

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 :

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)

        })

    }

解决方案

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 :

这篇关于为 UIImagePicker 添加圆形裁剪组件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:为 UIImagePicker 添加圆形裁剪组件?

基础教程推荐