GithubHelp home page GithubHelp logo

Comments (2)

babbage avatar babbage commented on June 16, 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.

from tocropviewcontroller.

zewkini avatar zewkini commented on June 16, 2024

@babbage - I agree this may very well work fine with SwiftUI but I don't use SwiftUI. I use plain Swift for all my programming as of now plus I'm checking this out for a Mac Catalyst app. I noticed that CropViewController initializes with a modalPresentationStyle of .overFullScreen. This is fine and seems to be overridden correctly on iOS devices when I specifiy the presentation style after initializing the CropViewController.

This doesn't work correctly when running on Mac Catalyst simulation with split view controller (3-column vc). Using .overCurrentContext for the secondary view controller does not initially position the CropViewController correctly.

What I did to solve the issue was this in CropViewController swift file:

...

extension CropViewController {
    fileprivate func setUpCropController() {
        
    #if targetEnvironment(macCatalyst)
        return
    #endif
        
        
        modalPresentationStyle = .overFullScreen

...

This seems to have solved the Catalyst issue. If Catalyst is runnning there is no need to execute any other setup code in the function as far as I can tell.

Thank you for your suggestions!

from tocropviewcontroller.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.