繁体   English   中英

SwiftUI 表格中的部分转换

[英]Section transition in SwiftUI Form

Form中的Section过渡始终是左右的,在某些情况下我想将其更改为左右,我尝试使用.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))
        
    }
}

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM