Интеграция UIViewController с раскадровкой в ​​проект SwiftUI: пробел наверху после перехода - PullRequest
1 голос
/ 18 июня 2020

У меня есть образец проекта 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

Если я перейду по ссылке, я буду перенаправлен на ViewVontroller. Это хорошо, за исключением того, что у меня большой разрыв наверху. Откуда это взялось и как от него избавиться? Спасибо.

1 Ответ

0 голосов
/ 18 июня 2020

Я предполагаю, что это пустая большая область заголовка NavigationView, поэтому просто скройте ее

    NavigationView {
        VStack {
            NavigationLink(destination: HomeViewControllerRepresentation()) {
                Text("Tap me")
            }
        }
        .navigationBarTitle("")
        .navigationBarHidden(true)
    }
...