I need to use some "uikit view controller" in my swiftui app. I have encapsulate the vc in a representable view. It works well. However, the background color will extend outside of safe area when I rotate the simulator from portrait to landscape and back to portrait.
I want the background color always to stay inside safe area. I prototype a sample code to illustrate the issue.
struct ContentView: View {
var body: some View {
ZStack{
Color.gray
CustomRepresentation()
}
}
}
struct CustomRepresentation: UIViewControllerRepresentable{
func makeUIViewController(context: Context) -> some UIViewController {
return UIViewController()
}
func updateUIViewController(_ uiViewController: UIViewControllerType, context: Context) {
}
}
If I comment the CustomRepresentation(), the gray color will stay inside the safe area all the time during rotating. So I realize the key point is CustomRepresentation(). But I don't know how to fix it.