Swiftui 目标中的快捷界面、导航视图和动画过渡。VStack有效,但列表无效

Swiftui 目标中的快捷界面、导航视图和动画过渡。VStack有效,但列表无效,swiftui,transition,Swiftui,Transition,如果我使用列表,则RoundedRectangle“动画输出”但“捕捉”。 它是一个SwiftUI bug还是我 此外,如果第三个导航链接被注释掉,则矩形视图中的按钮会将应用程序弹出回导航视图。下次我去矩形的时候,它已经改变了颜色。 这仅在VStack中发生,列表不受影响。 这毫无意义 import SwiftUI struct ContentView: View { @State var fff: Bool = false var body: some View {

如果我使用列表,则RoundedRectangle“动画输出”但“捕捉”。 它是一个SwiftUI bug还是我

此外,如果第三个导航链接被注释掉,则矩形视图中的按钮会将应用程序弹出回导航视图。下次我去矩形的时候,它已经改变了颜色。 这仅在VStack中发生,列表不受影响。 这毫无意义

import SwiftUI

struct ContentView: View {
    @State var fff: Bool = false
    var body: some View {
        NavigationView {
            VStack { // <---- This works if I have three navigation links, but not if I have only two.
//          List { // <------ This does not work.
                NavigationLink(
                    destination:
                        ZStack {
                            if fff {
                                RoundedRectangle(cornerRadius: 100) .foregroundColor(.blue)
                                    .transition(.asymmetric(insertion: .move(edge: .bottom), removal: .move(edge: .top)))
                                    .animation(.easeIn)
                            }
                            else {
                                RoundedRectangle(cornerRadius: 100) .foregroundColor(.purple)
                                    .transition(.asymmetric(insertion: .move(edge: .bottom), removal: .move(edge: .top)))
                                    .animation(.easeIn)
                            }
                            Button(action: {
                                fff.toggle()
                            }, label: {
                                Text("Button")
                            })
                        }
                    ,
                    label: {
                        Text("To rectangles")
                    }
                )
                NavigationLink(
                    destination: Text("Settings"),
                    label: {
                        HStack {
                            Image(systemName: "wrench")
                            Text("Settings")
                        }
                    }
                )
//              NavigationLink( <--- If this link is commented out then the button in the rectangles view pops the app back to the Navigation view (only when using VStack).
//                  destination: Text("Store"),
//                  label: {
//                      HStack {
//                          Image(systemName: "cart")
//                          Text("Store")
//                      }
//                  }
//              )
            }
        }
    }
}
导入快捷界面
结构ContentView:View{
@状态变量fff:Bool=false
var body:一些观点{
导航视图{

VStack{/将目标移动到另一个结构可以解决此问题

struct RectView: View {
    @State var fff: Bool = false
    var body: some View {
        ZStack {
            if fff {
                RoundedRectangle(cornerRadius: 100) .foregroundColor(.blue)
                    .transition(.asymmetric(insertion: .move(edge: .bottom), removal: .move(edge: .top)))
                    .animation(.easeIn)
            } else {
                RoundedRectangle(cornerRadius: 100) .foregroundColor(.purple)
                    .transition(.asymmetric(insertion: .move(edge: .bottom), removal: .move(edge: .top)))
                    .animation(.easeIn)
            }
            Button(action: {
                fff.toggle()
            }, label: {
                Text("Button")
            })
        }
    }
}

谢谢。我以为我已经试过了,但你做得更好:)