【发布时间】:2021-07-30 21:27:36
【问题描述】:
在 SwiftUI 中,有几种方法可以呈现模态视图,例如 .popover。
我的背景是我想在其他地方而不是在当前视图页面下展示 UIKit 模式视图
private func presentGlobally(animated: Bool, completion: (() -> Void)?) {
var rootViewController = UIApplication.shared.rootViewController
while true {
if let presented = rootViewController?.presentedViewController {
rootViewController = presented
} else if let navigationController = rootViewController as? UINavigationController {
rootViewController = navigationController.visibleViewController
} else if let tabBarController = rootViewController as? UITabBarController {
rootViewController = tabBarController.selectedViewController
} else {
break
}
}
UIApplication.shared.rootViewController?.present(self, animated: animated, completion: completion)
}
上述方法不起作用,因为 SwiftUI 给出了错误
``[演示]尝试本 所以我在想
【问题讨论】: