Tocropviewcontroller: Swift Delegate Method

Created on 8 Jul 2017  ·  3Comments  ·  Source: TimOliver/TOCropViewController

Hi I am currently on swift 3 and am having some issues with creating a circular crop view controller through the delegate method. Can someone please just show me their code for doing so along with the functions called that contain the newly cropped image. Thanks so much!

question

Most helpful comment

@srosman8026 , for example

extension YourVC : TOCropViewControllerDelegate {
    func openCrop(image: UIImage) {
        let crop = TOCropViewController(croppingStyle: .circular, image: image)
        crop.delegate = self
        present(crop, animated: true, completion: nil)
    }

    func cropViewController(_ cropViewController: TOCropViewController, didCropToCircleImage image: UIImage, rect cropRect: CGRect, angle: Int) {
        cropViewController.dismiss(animated: true, completion: {
            self.updatePhoto(image: image)
        })
    }

    func cropViewController(_ cropViewController: TOCropViewController, didFinishCancelled cancelled: Bool) {
        cropViewController.dismiss(animated: true, completion: {

        })
    }
}

All 3 comments

@srosman8026 , for example

extension YourVC : TOCropViewControllerDelegate {
    func openCrop(image: UIImage) {
        let crop = TOCropViewController(croppingStyle: .circular, image: image)
        crop.delegate = self
        present(crop, animated: true, completion: nil)
    }

    func cropViewController(_ cropViewController: TOCropViewController, didCropToCircleImage image: UIImage, rect cropRect: CGRect, angle: Int) {
        cropViewController.dismiss(animated: true, completion: {
            self.updatePhoto(image: image)
        })
    }

    func cropViewController(_ cropViewController: TOCropViewController, didFinishCancelled cancelled: Bool) {
        cropViewController.dismiss(animated: true, completion: {

        })
    }
}

Yep! @drougojrom is correct! Thanks for that! :)

It might be best to make a Swift example project as well...

@TimOliver , I have the separate swift project, a small one, just for demonstration. Can upload it on the separate repository or add inside of your project.

I can open a new issue for that.

Was this page helpful?
0 / 5 - 0 ratings