TimOliver / TOCropViewController

A view controller for iOS that allows users to crop portions of UIImage objects
http://www.timoliver.com.au/2015/06/21/tocropviewcontroller-an-open-source-image-cropper-for-ios/
MIT License
4.67k stars 929 forks source link

How do you match foreground to background? #560

Closed devshaww closed 3 months ago

devshaww commented 9 months ago

What are you trying to achieve with this library exactly? Please describe. I might get this wrong.

From what I can understand, matching foreground to background is to make 2 images move and scale together so that they look like one image. But how did you match them?

According to the content of matchForegroundToBackground: self.backgroundContainerView.superview is exactly scrollview right? But I think the frame of backgroundContainerView does not change(what changes is the contentOffset)so I don't quiet understand.

Thanks in advance! That'll be of great help.

TimOliver commented 3 months ago

Hi @devshaww! All the code for matching the two is here: https://github.com/TimOliver/TOCropViewController/blob/7bce8f02107ef57087136b927ca4a55e864de9ae/Objective-C/TOCropViewController/Views/TOCropView.m#L402-L411

Admittedly, if I was to rebuild this library today, I probably wouldn't do it like that again. It was good for performance in 2015, but it ended up being really messy to handle things like rotations with.