Share Extension Modal Presentation Style iOS 13 is not working

Viewed 1456

I implemented the share extension and I want animate my View Controller with a crossDissolve, so i set the modalPresentationStyle = .overFullScreen and modalTransitionStyle = crossDissolve but it seems not working. The VC still appear from the bottom to the top and with the new iOS 13 modal style (not completly full screen). Anyone know how to solve it? It tried both with and without storyboard.

NB: I'm not talking about a normal VC presentation, but the presentation of the share extension, it means that it's another app that present my VC.

1 Answers

One way to do it would be to have the system presented viewcontroller as a container.

And then present your content viewcontroller inside modally.

// this is the entry point
// either the initial viewcontroller inside the extensions storyboard
// or
// the one you specify in the .plist file
class ContainerVC: UIViewController {

    // afaik presenting in viewDidLoad/viewWillAppear is not a good idea, but this produces the exact result you are looking for.
    // meaning the content slides up when extension is triggered.
    override func viewWillAppear() {
        super.viewWillAppear()

        view.backgroundColor = .clear

        let vc = YourRootVC()
        vc.view.backgroundColor = .clear
        vc.modalPresentationStyle = .overFullScreen
        vc.loadViewIfNeeded()
        present(vc, animated: false, completion: nil)
    }

}

and then use the content viewcontroller to show your root viewcontroller and its view hierarchy.

class YourRootVC: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()

        let vc = UIViewController() // your actual content
        vc.view.backgroundColor = .blue
        vc.view.frame = CGRect(origin: vc.view.center, size: CGSize(width: 200, height: 200))
        view.addSubview(vc.view)
        addChild(vc)
    }

}

Basically a container and a wrapper in order to get the control over the views being displayed.

Source: I had the same problem. This solution works for me.

Related