Skip to content
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

Request To Allow User To Change Modal Presentation Style Of CropViewController #564

Open
zewkini opened this issue Feb 13, 2024 · 1 comment
Assignees
Labels

Comments

@zewkini
Copy link

zewkini commented Feb 13, 2024

Good work. Even works well in Mac Catalyst, but:

Would be nice to let the user define the way the CropViewController is presented. Right now it is .fullScreen.

It might be useful (in Mac Catalyst) to be able to use .overCurrentContext or other presentation styles when you are using a splitviewcontroller so the cropview doesn't cover up the entire splitview when that behavior isn't desirable. Maybe a .preferredContentSize for the view.

@babbage
Copy link

babbage commented May 29, 2024

I wanted this same ability, and found it is indeed possible to do so.

After instantiating your instance of CropViewController, simply set the preferred .modalPresentationStyle before displaying the controller.

For instance, here is my method that I use to trigger image cropping:

        func crop(_ image: UIImage) {
            let cropViewController = CropViewController(image: image)
            cropViewController.modalPresentationStyle = .currentContext
            cropViewController.delegate = self
            present(cropViewController, animated: true, completion: nil)
        }

With this change, the CropViewController—which is being instantiated by a UIViewController inside a UIViewControllerRepresentable— appears contained within a SwiftUI-presented .sheet, fills that sheet but not the whole screen, and when dismissed that sheet's underlying contents are correctly displayed again, which did not happen with the default full screen presentation style.

Thanks for making all this work, Tim! Love it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants