共享扩展模态呈现样式在iOS 13上无法工作

7
我实现了分享扩展并希望用交叉溶解的方式来动画显示我的视图控制器,所以我设置了modalPresentationStyle = .overFullScreenmodalTransitionStyle = crossDissolve,但似乎没有起作用。视图控制器仍然从底部到顶部出现,并且呈现的样式是新的iOS 13模态样式(不完全全屏)。 有人知道如何解决吗? 我尝试使用和不使用Storyboard,均未成功。
注:我说的不是普通的VC呈现,而是分享扩展的呈现,这意味着是另一个应用程序呈现我的VC。

@DavidChopin 这是一个共享文件的应用程序,它展示了我的“扩展”,所以我不知道使用了哪种展示方法。(例如:转到“语音备忘录”并按“分享”,然后选择我的应用程序)。 我只是在我的VC属性中选择了“modalPresentationStyle”和“modalTransitionStyle”。 你的例子只是一个普通的展示。 - Fab
啊,我明白了。你能分享一些你如何实现这个的代码吗? - David Chopin
请问这个有任何更新吗? - Ankit Mehta
我们遇到了同样的问题。你使用的Xcode版本是哪个? - GPRyan
我遇到了同样的问题,我尝试了我能想到的一切,但共享扩展总是以.coverVertical动画模态呈现。我甚至尝试在我使用的UIViewController子类上执行此类操作,它被调用了,但仍然不起作用:override var modalPresentationStyle: UIModalPresentationStyle { set { } get { .fullScreen } } override var modalTransitionStyle: UIModalTransitionStyle { set { } get { .crossDissolve } } - Xavi Moll
显示剩余6条评论
1个回答

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

}

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

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

}

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

来源:我曾经有同样的问题。这个解决方案对我有效。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接