SwiftUI 表单中的部分转换

Sor*_*ica 11 animation ios swift swiftui

Section转型Form总是左右,我想将其更改为从右向左在某些情况下,我尝试.transition.move修改器,但它不会有效果。

struct ContentView: View {
    
    @State var visible = true

    var body: some View {
        
        Form {
            Button("visible") {
                self.visible.toggle()
            }
            visible ? Section {
                Text("Section 1")
                Text("Section 1")
            }.transition(.move(edge: .leading)) : nil
            !visible ? Section {
                Text("Section 2")
                Text("Section 2")
            }.transition(.move(edge: .trailing)) : nil
            Section {
                Text("Section 3")
                Text("Section 3")
            } // Section 3 should not be animated
        }.animation(.linear(duration: 0.5))
        
    }
}
Run Code Online (Sandbox Code Playgroud)

Mal*_*ard 1

我阅读了大量 Apple 的 SwiftUI 表单代码文档,发现定制选项很少;特别是您当前设置代码的方式。在这方面,我建议从头开始创建动画和页面。这样做,您将在过渡方向上拥有完全的创作自由。这需要做很多工作才能看起来像一个表单,但这是可能的。以下答案将为您提供从右到左的过渡:/sf/answers/4350145761/