У меня есть образец проекта SwiftUI , чтобы узнать, могу ли я перейти от SwiftUI View
к UIKit UIViewController
. И я могу.
Вот мой UIViewController
.
import UIKit
import SwiftUI
class HomeViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
view.backgroundColor = UIColor.orange
}
}
struct HomeViewControllerRepresentation: UIViewControllerRepresentable {
func makeUIViewController(context: UIViewControllerRepresentableContext<HomeViewControllerRepresentation>) -> HomeViewController {
UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "homeViewController") as! HomeViewController
}
func updateUIViewController(_ uiViewController: HomeViewController, context: UIViewControllerRepresentableContext<HomeViewControllerRepresentation>) {
}
}
И у меня есть SwiftUI View
, как показано ниже.
import SwiftUI
struct ContentView: View {
var body: some View {
NavigationView {
VStack {
NavigationLink(destination: HomeViewControllerRepresentation()) {
Text("Tap me")
}
}
}
}
}
![enter image description here](https://i.stack.imgur.com/vCYBK.jpg)
Если я перейду по ссылке, я буду перенаправлен на ViewVontroller
. Это хорошо, за исключением того, что у меня большой разрыв наверху. Откуда это взялось и как от него избавиться? Спасибо.