Open sabiland opened 3 years ago
It would be really cool if there was an option-logic for cropping to exact dimensions.
Anyways, great library !
Feel free to do that yourself and make a pull request.
Well sorry mate, besides my regular programming job I work also on my iOS app a lot, I do not have time to do it alone.
It is really a nice library, I integrated it into my app in 5 minutes :).
Thanks for the feedback @sabiland! I'm glad you're enjoying the library.
Hmm, how exactly do you mean cropping to exact dimensions exactly? How would you see this working?
Haha, I also share the same sentiments about spending time between work and my iOS side projects. 🤣
Well I was thinking just to choose exact width/height (in pixels) for cropping and then you would just move fixed rectangle around image. Though I am not sure if this feature would be helpful for most of the users.
I needed a subset of this functionality: specifying a minimum pixel dimension. That can be obtained by configuring the TOCropViewController
/TOCropView
as follows:
let image: UIImage = ...
let cropController: TOCropViewController = ...
let minimumSize: CGSize = ...
cropController.aspectRatioLockEnabled = true
cropController.customAspectRatio = minimumSize
cropController.allowedAspectRatios = [
NSNumber(value: TOCropViewControllerAspectRatioPreset.presetCustom.rawValue)
]
let wRatio = image.size.width / minimumSize.width
let hRatio = image.size.height / minimumSize.height
cropController.cropView.maximumZoomScale = min(wRatio, hRatio)
Though I wouldn't mind a more straightforward way of specifying that supported directly by TOCropView
, that code works for me.
If you really needed an exact height and width (which I don't, so I'm not going to write the code to do it), at a glance it seems like the most straightforward way would be to add a minimumZoomScale
property to the TOCropView
, and connect it to the underlying scrollView in -[TOCropView layoutInitialImage]
and -[TOCropView moveCroppedContentToCenterAnimated:]
. Then, set both the minimum and maximum zoom scales to the same value.
It would be really cool if there was an option-logic for cropping to exact dimensions.
Anyways, great library !