Add a circular cropping component for UIImagePicker?

后端 未结 3 551
刺人心
刺人心 2020-12-13 16:43

I Have a circular framed UIImageView and I need to add a circular framed cropping tool for the UIImagePickerController, after the image is selected

3条回答
  •  臣服心动
    2020-12-13 17:42

    Kirit Modi's answer was exactly what I needed, although I needed to do one thing to make this work. For those that dont download the test project, make sure to implement your delegate methods:

    Swift 3:

    extension YourViewControllerClass: RSKImageCropViewControllerDelegate {
    
        func imageCropViewControllerDidCancelCrop(_ controller: RSKImageCropViewController) {
            _ = self.navigationController?.popViewController(animated: true)
        }
    
        func imageCropViewController(_ controller: RSKImageCropViewController, didCropImage croppedImage: UIImage, usingCropRect cropRect: CGRect) {
            self.avatarImageView.image = croppedImage
            _ = self.navigationController?.popViewController(animated: true)
        }
    
    }
    

    Swift 2:

    extension YourViewControllerClass: RSKImageCropViewControllerDelegate {
    
        func imageCropViewControllerDidCancelCrop(controller: RSKImageCropViewController) {
            self.navigationController?.popViewControllerAnimated(true)
        }
    
        func imageCropViewController(controller: RSKImageCropViewController, didCropImage croppedImage: UIImage, usingCropRect cropRect: CGRect) {
            self.avatarImageView.image = croppedImage
            self.navigationController?.popViewControllerAnimated(true)
        }
    
    }
    

提交回复
热议问题