ruslanskorb / RSKImageCropper

An image cropper / photo cropper for iOS like in the Contacts app with support for landscape orientation.
MIT License
2.45k stars 471 forks source link

Circlemask center, width etc. + Cancel button completion boolean? #235

Closed MatteoJ closed 3 years ago

MatteoJ commented 3 years ago

Dear all,

Firstly, I am trying to make a circular profile picture cropper like advertised on the readme of this repository. While it works perfectly, I need some extra information on the circular mask (like the location of the mask center, width, ...). Unfortunately, I cannot seem to find it myself. I only find this info for rectangular masks, but these values are all 0 for the circle. Below is a snippet of my code.

Secondly, I would like to know whether or not the cancel button inside the cropper has been pushed, since I would like to do something in this case. I have also been unsuccessful in finding out how this works.

Thank you so much in advance,

M.

func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey : Any]) {

        picker.dismiss(animated: true, completion: nil)

        guard let selectedImage = info[UIImagePickerController.InfoKey.originalImage] as? UIImage else {
            return
        }

        picker.dismiss(animated: true, completion: { () -> Void in
            var imageCropVC : RSKImageCropViewController!
            imageCropVC = RSKImageCropViewController(image: selectedImage, cropMode: RSKImageCropMode.circle)
            imageCropVC.delegate = self
            self.navigationController?.pushViewController(imageCropVC, animated: true)

            self.ProfilePicture.image = selectedImage
        })

    }
ruslanskorb commented 3 years ago

Hi @MatteoJ,

RSKImageCropViewController has a property maskRect , that is updated each time before the crop view lays out its subviews. So, you need to wait for the crop view to do this at least once.

Regarding your second question, RSKImageCropViewControllerDelegate has a method imageCropViewControllerDidCancelCrop(_:) that is called when the user taps the Cancel button.