SwiftUI-丑陋的动画从纵向切换到横向

SwiftUI-丑陋的动画从纵向切换到横向,swiftui,Swiftui,我有这个iPhone应用程序,我想有两个视图,一个是纵向视图,一个是横向视图。因此,我在ContentView上有以下内容: struct ContentView: View { var body: some View { Group { GeometryReader { geometry in if (geometry.size.width > geometry.size.height) {

我有这个iPhone应用程序,我想有两个视图,一个是纵向视图,一个是横向视图。因此,我在ContentView上有以下内容:

struct ContentView: View {
    var body: some View {          
      Group {
        GeometryReader { geometry in
          if (geometry.size.width > geometry.size.height) {
            ZStack {
              Color.red
                .edgesIgnoringSafeArea(.all)
              
              Text("LANDSCAPE")
                .font(.title)
                .foregroundColor(.white)
            }
          }
          
          if (geometry.size.width < geometry.size.height) {
            
            ZStack {
              Color.blue
                .edgesIgnoringSafeArea(.all)
              
              Text("PORTRAIT")
                .font(.title)
                .foregroundColor(.white)
            }
          }
        }
      }
      .background(Color.black.edgesIgnoringSafeArea(.all))
    }
}
struct ContentView:View{
变量体:某些视图{
团体{
GeometryReader{中的几何体
if(geometry.size.width>geometry.size.height){
ZStack{
颜色:红色
.edgesIgnoringSafeArea(.all)
文本(“景观”)
.font(.title)
.foregroundColor(.白色)
}
}
if(几何体.尺寸.宽度<几何体.尺寸.高度){
ZStack{
蓝色
.edgesIgnoringSafeArea(.all)
文字(“肖像”)
.font(.title)
.foregroundColor(.白色)
}
}
}
}
.背景(颜色.黑色.边缘识别安全区域(.all))
}
}
当iPhone旋转时,我有一个丑陋的动画:

我不喜欢从边上看,然后像那样旋转。 有什么方法可以让视图看起来像是在适当的位置,只需更改颜色和文本


有什么办法可以改进这一点并创造出更漂亮的东西吗?

这里有一个可能的解决方案——只是改变了旧容器的组合

使用Xcode 12.1/iOS 14.1进行测试

struct ContentView:View{
var body:一些观点{
GeometryReader{gp in
ZStack{
LANDSCAPEView().不透明度(gp.size.width>gp.size.height?1.0:0)
肖像视图().不透明度(gp.size.width
谢谢。你的回答给了我很多想法。
struct ContentView: View {
    var body: some View {
        GeometryReader { gp in
            ZStack {
                LANDSCAPEView().opacity(gp.size.width > gp.size.height ? 1.0 : 0)
                PORTRAITView().opacity(gp.size.width < gp.size.height ? 1.0 : 0)
            }
        }
        .frame(maxWidth: .infinity, maxHeight: .infinity)
        .animation(.default)
        .background(Color.black.edgesIgnoringSafeArea(.all))
    }
}

struct LANDSCAPEView: View {
    var body: some View {
        Color.red
            .overlay(
                
                Text("LANDSCAPE")
                    .font(.title)
                    .foregroundColor(.white)
            )
            .edgesIgnoringSafeArea(.all)
    }
}

struct PORTRAITView: View {
    var body: some View {
        Color.blue.overlay(
            
            Text("PORTRAIT")
                .font(.title)
                .foregroundColor(.white)
        )
        .edgesIgnoringSafeArea(.all)
    }
}