简体   繁体   中英

Section transition in SwiftUI Form

The Section transition in Form is always left-right, I would like to change it to right-left in some cases, I tried .transition with .move modifier, but it does not have effect.

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))
        
    }
}

I read through a significant amount of Apple's code documentation for SwiftUI forms and it appears that there are very few options for customization; specifically with the way you have the code currently set up. In that, I would recommend creating the animations and page from scratch. Doing it that way, you would have complete creative freedom of the directions for the transitions. This would take a lot of work to look like a Form, but it's possible. The following answer will give you a right-left transition: https://stackoverflow.com/a/62144939/13296047

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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