【发布时间】:2022-12-16 01:50:06
【问题描述】:
我正在尝试显示一个 UIHostingController,它在屏幕上显示我的 SwiftUI 弹出窗口 - 但是,演示文稿出现故障并且显示的视图控制器卡在左上角的某个地方(见图,出现故障的托管控制器位于红色圆圈内)。
只有在我的托管控制器之前显示另一个 View 控制器时才会发生这种情况。因此,如果在我的托管控制器之前没有显示任何内容,则一切正常。
如果我设置我的 UIHostingController 的 modalPresentationStyle = .formSheet,事情也能正常工作 - 但是,这对我来说不是解决方案,因为我的用例需要 .overCurrentContext 的行为。
所以,简而言之,我遇到故障什么时候:
-
在某个时候会出现一个任意视图控制器(使用
self.present(...)) -
前我的
UIHostingViewController出现了。
我不要在以下情况下出现该故障:
- 我只显示 UIHostingViewController
代码
我使用以下代码收到描述的行为:
// First, I display an ActivitySheet
let ac = UIActivityViewController(activityItems: [someItems], applicationActivities: nil)
self.present(ac, animated: true)
// then I present my ViewController using overCurrentContext, after the ActivityViewController was dismissed
let myPopupVC = MyPopupVC()
myPopupVC.isModalInPresentation = true
myPopupVC.modalPresentationStyle = .overCurrentContext // error would not occur if this was .formSheet, but I need .overCurrentContext for my use case.
myPopupVC.modalTransitionStyle = .crossDissolve
self.definesPresentationContext = true
self.present(self, animated: true)
这两种模式呈现都是在我的界面中单击按钮的结果。单击共享按钮时显示UIActivityViewController,按下离开按钮时显示弹出窗口(以确认用户确定他们想要这样做)。
我的假设
我的第一个想法是,这可能与被解雇的活动表所呈现的 UIHostingController 有关,但是,这没有意义,因为它根据 Apple's documentation 在视图控制器解雇时从内存中释放(第“关闭已呈现的视图控制器”).
因此,我不明白为什么会这样。
有谁知道为什么会出现这种行为,最重要的是,我该如何解决使用.overCurrentContext 作为我的模式呈现风格?
【问题讨论】:
标签: ios swift swiftui uiviewcontroller uikit