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

Fab*_*Fab 7 xcode share ios swift share-extension

我实现了共享扩展,我想用 a 为我的视图控制器设置动画crossDissolve,所以我设置了modalPresentationStyle = .overFullScreenmodalTransitionStyle = crossDissolve但它似乎不起作用。VC 仍然从底部到顶部出现,并采用新的 iOS 13 模态样式(不是完全全屏)。有谁知道如何解决它?它尝试了有和没有故事板。

注意:我不是在谈论普通的 VC 演示,而是 的演示share extension,这意味着它是另一个展示我的 VC 的应用程序。

iOS*_*ith 1

一种方法是让系统将视图控制器呈现为容器。

然后以模态方式在内部呈现您的内容视图控制器。

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

}
Run Code Online (Sandbox Code Playgroud)

然后使用内容视图控制器显示您的根视图控制器及其视图层次结构。

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

}
Run Code Online (Sandbox Code Playgroud)

基本上是一个容器和一个包装器,以便控制所显示的视图。

来源:我也遇到了同样的问题。这个解决方案对我有用。