简体   繁体   English

共享扩展模态演示样式 iOS 13 不起作用

[英]Share Extension Modal Presentation Style iOS 13 is not working

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.我实现了共享扩展,我想用crossDissolve为我的 View Controller 设置动画,所以我设置了modalPresentationStyle =.overFullScreenmodalTransitionStyle = crossDissolve但它似乎不起作用。 The VC still appear from the bottom to the top and with the new iOS 13 modal style (not completly full screen). VC 仍然从下到上出现,并带有新的 iOS 13 模态样式(不完全全屏)。 Anyone know how to solve it?有谁知道如何解决它? It tried both with and without storyboard.它尝试了使用和不使用 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.注意:我说的不是普通的 VC 演示,而是share extension的演示,这意味着它是另一个应用程序演示我的 VC。

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.这个解决方案对我有用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM