Tocropviewcontroller: Show circle area but crop with rect?

Created on 15 Sep 2017  ·  5Comments  ·  Source: TimOliver/TOCropViewController

Hi all!

I would like to know if it's possibe to show the circular crop area to users but instead of getting the image cropped with a circle, just get it cropped with the min rectangle containing that circle, does that make sense?

Thanks!

question rfc

Most helpful comment

Dooh! Didn't know that the:

- (void)cropViewController:(TOCropViewController *)cropViewController didCropToImage:(UIImage *)image withRect:(CGRect)cropRect angle:(NSInteger)angle

delegate was called even if I set the the crop area to circular :)

Thanks a lot Tim! Cheers!

Agus.

All 5 comments

Hi @agusguerra10!

If you just want the CGRect value from an image, even in circular mode, you just need to implement the - (void)cropViewController:(TOCropViewController *)cropViewController didCropImageToRect:(CGRect)cropRect angle:(NSInteger)angle delegate method. :)

You can also implement - (void)cropViewController:(TOCropViewController *)cropViewController didCropToImage:(UIImage *)image withRect:(CGRect)cropRect angle:(NSInteger)angle if you want a square copy of that image.

Hope that helped! Let me know if you were looking for something else!

Dooh! Didn't know that the:

- (void)cropViewController:(TOCropViewController *)cropViewController didCropToImage:(UIImage *)image withRect:(CGRect)cropRect angle:(NSInteger)angle

delegate was called even if I set the the crop area to circular :)

Thanks a lot Tim! Cheers!

Agus.

really?
i am looking for the answer to this question.
i have set the style circular.
but not call the delegate function
func cropViewController(_ cropViewController: TOCropViewController, didCropToImage image: UIImage, rect cropRect: CGRect, angle: Int)

i have solved the problem

  • (void)cropViewController:(TOCropViewController *)cropViewController didCropImageToRect:(CGRect)cropRect angle:(NSInteger)angle

this delegate method will be called even if set the crop area to circular.
in the delegate i use the - (nonnull UIImage *)croppedImageWithFrame:(CGRect)frame angle:(NSInteger)angle circularClip:(BOOL)circular;
to crop it to get the rect image. but need set circularClip to false.

i want to ask Tim,it is right?
what agusguerra10 said is not called in my project. xcode9 swift4.

  • (void)cropViewController:(TOCropViewController *)cropViewController didCropToImage:(UIImage *)image withRect:(CGRect)cropRect angle:(NSInteger)angle
    i tested the example code also. it will be not called also if u set the style circular

No worries @agusguerra10! Yeah, in retrospect, it wasn't a great pattern basing logic on which delegate methods the delegate implemented; it's caused a little bit of confusion. 😅

@agusguerra10 I just checked the code for handling delegate callbacks. That's correct. If you implement any of the circular delegate methods in circular mode, then the one that returns a square image is ignored.

If you think this should be changed, it might be better to track it in a new issue. Thanks! :)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

mugunth87 picture mugunth87  ·  5Comments

asadqazi picture asadqazi  ·  3Comments

felipebonezi picture felipebonezi  ·  6Comments

piyushlodaliya picture piyushlodaliya  ·  3Comments

erickva picture erickva  ·  4Comments