共享扩展模式演示样式 iOS 13 无法正常工作



我实现了共享扩展,我想用crossDissolve对我的视图控制器进行动画处理,所以我设置了modalPresentationStyle = .overFullScreenmodalTransitionStyle = crossDissolve但它似乎不起作用。VC 仍然从下到上显示,并采用新的 iOS 13 模式样式(不是完全全屏(。 有人知道如何解决它吗?它尝试了有和没有故事板。

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

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

然后以模式方式在里面展示您的内容视图控制器。

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

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

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

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

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

最新更新