gpt4 book ai didi

ios - 为 UIImagePicker 添加圆形裁剪组件?

转载 作者:行者123 更新时间:2023-11-28 08:11:09 25 4
gpt4 key购买 nike

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

更新

我发现这个 repo 有一个圆形裁剪工具 https://github.com/ruslanskorb/RSKImageCropper

但是有人可以指导我如何在用户从照片库中选择照片后使用 UIImagePickerController 实现这个裁剪工具吗?

更新

我在调试器中收到以下消息:

enter image description here

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

这是我的代码:

  @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

是的,您可以在 UIImagePickerController 中添加 RSKImageCropper

定义imagePicker

var imagePicker : UIImagePickerController!

ViewDidLoad

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

委托(delegate)方法:

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)

})

}

见:

enter image description here

关于ios - 为 UIImagePicker 添加圆形裁剪组件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43718769/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com