TOCropViewController
TOCropViewController copied to clipboard
Move TOCropViewControllerAspectRatioPreset to a class and make it configurable
Now it's possible to use completely custom aspect ratio presets:
cropViewController.allowedAspectRatios = [
.init(size: CGSize(width: 1024, height: 768).normalized(), title: "Landscape"),
.init(size: CGSize(width: 768, height: 1024).normalized(), title: "Portrait"),
]
Don't forget that aspect ratios need to be normalized (i.e., the width and height of the size should be in the range [0..1]).
private extension CGSize {
func normalized() -> CGSize {
if width == height {
CGSize(width: 1, height: 1)
} else if width > height {
CGSize(width: 1, height: height / width)
} else {
CGSize(width: width / height, height: 1)
}
}
}