我有一个圆形框架UIImageView
并且我需要为UIImagePickerController
添加一个圆形框架裁剪工具,在从照片库中选择图像之后。与Instagram的作物成分非常相似。如何添加此类组件?
更新
我找到了这个带有圆形裁剪工具的回购协议https://github.com/ruslanskorb/RSKImageCropper
但是,在用户从照片库中选择照片后,有人能指导我如何使用UIImagePickerController实现这个裁剪工具吗?
更新
我在调试器中收到以下消息:
我的裁剪视图中的按钮被禁用,这意味着我无法选择它们。。调试器传递给我的是什么消息?
这是我的代码:
@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
是的,您可以在RSKImageCropper
中添加UIImagePickerController
定义imagePicker
var imagePicker : UIImagePickerController!
在
ViewDidLoad
imagePicker = UIImagePickerController()
imagePicker.delegate = self
imagePicker.sourceType = UIImagePickerControllerSourceType.PhotoLibrary;
self.presentViewController(imagePicker, animated: true, completion: nil)
委托方式:
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)
})
}
见: