Skip to content

Move TOCropViewControllerAspectRatioPreset to a class and make it configurable #608

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

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

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.

1 participant