Home > AI > IOS > SwiftUI >

AnyTransition

Example 1: extension

import Foundation
import SwiftUI

extension AnyTransition {
    static var moveToOpacity: AnyTransition {
        let insertion = AnyTransition.move(edge: .bottom)
        let removal = AnyTransition.opacity
        return .asymmetric(insertion: insertion, removal: removal)
    }
}
struct PlayerView: View {
    @State private var show: Bool = false

    var body: some View {
        
            VStack {
                if show {
                    Text("good")
                        .transition(.moveToOpacity)
                }
                Button("Animate") {
                    withAnimation(.easeInOut(duration: 1.0)) {
                        self.show.toggle()
                    }
                }.padding(20)
            }
    }
}

Leave a Reply