Skip to content

Flip a View with animation to create a two side View illusion.

Notifications You must be signed in to change notification settings

nickpolychronakis/FlipAnimation

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Buy Me A Coffee

If you like it, consider to buy me a coffee!

FlipAnimation

With this function you can make any View to flip with a 3d rotation, and use it to create an illusion of a two side effect View.

Example

    import SwiftUI
    import FlipAnimation

    struct ContentView: View {
        
        // The side that we want to be shown
        @State private var frontSide = true
        
        var body: some View {
            VStack {
                if frontSide {
                    Text("Hello, World!")
                } else {
                    Text("Back Side Hello, World!")
                    // IMPORTANT: It's important to rotate the back side view 180 degrees
                    .rotation3DEffect(Angle(degrees: 180), axis: (x: 0, y: 1, z: 0))
                }
            }
            .frame(width: 300, height: 250)
            .background(Color.blue)
            .cornerRadius(30)
            .onTapGesture {
                self.frontSide.toggle()
            }
            // The func that flips the view
                .flip(frontSideVisible: frontSide, duration: 2.0)
        }
    }

About

Flip a View with animation to create a two side View illusion.

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages