问题描述
我在 Storyboard Swift 应用程序上工作,想要以全屏方式呈现 SwiftUI 子视图。我使用 UIHostingController
嵌入了 SwiftUI 视图,如下所示:
let contentView = UIHostingController(rootView: ContentView())
override func viewDidLoad() {
super.viewDidLoad()
addChild(contentView)
view.addSubview(contentView.view)
}
这是我的 SwiftUI ContentView()
子视图:
import SwiftUI
import UIKit
struct ContentView: View {
var body: some View {
Text("").fullScreenCover(isPresented: /*@START_MENU_TOKEN@*/.constant(true)/*@END_MENU_TOKEN@*/,content: {
FullScreenView.init()
})
}
}
struct FullScreenView: View{
var body: some View {
NavigationView{
MasterView()
}.navigationViewStyle(DoubleColumnNavigationViewStyle())
}
}
struct MasterView: View {
var body: some View {
Form {
Section(header: Text("HEADER")) {
Section {
NavigationLink(destination: UIKitView()) { Text("NAVLINK TEXT") }
}
}
}
.navigationBarTitle("NAVBAR TEXT")
}
}
struct UIKitView: UIViewControllerRepresentable {
typealias UIViewControllerType = swipeviewController
func makeUIViewController(context: Context) -> swipeviewController {
let sb = UIStoryboard(name: "Storyboard",bundle: nil)
let viewController = sb.instantiateViewController(identifier: "vc") as! swipeviewController
return viewController
}
func updateUIViewController(_ uiViewController: swipeviewController,context: Context) {
}
}
有没有更好的方法来做到这一点?如您所见,我使用空文本字段添加 .fullScreenCover :/
感谢您的帮助!!
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)