Skip to content

Conversation

glyuck
Copy link

@glyuck glyuck commented Apr 28, 2025

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)
        }
    }
}

@TimOliver
Copy link
Owner

Oh wow! This is excellent! Thanks so much for that @glyuck!

@TimOliver TimOliver merged commit 83298c5 into TimOliver:main Sep 28, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants