SwiftUI的转场动画
SwiftUI的转场动画
记录一下SwiftUI中的一些弹窗动画
import SwiftUIstruct TransitionBootCamp: View {@State var showView = falselet screenWidth = UIScreen.main.bounds.widthlet screenHeight = UIScreen.main.bounds.heightvar body: some View {ZStack(alignment: .bottom, content: {VStack{Button("Button") {showView.toggle()}Spacer()}if showView {RoundedRectangle(cornerRadius: 25.0).ignoresSafeArea().frame(height: screenHeight * 0.5)/// 从底部升上去.transition(AnyTransition.move(edge: .bottom)).animation(.bouncy)/// 透明度渐变出现
// .transition(AnyTransition.opacity.animation(.default))/// 比例出现
// .transition(AnyTransition.scale.animation(.default))/// 控制出来和结束方向 左进下出
// .transition(.asymmetric(insertion: .move(edge: .leading), removal: .move(edge: .bottom)))
// .animation(.easeInOut)}})}
}#Preview {TransitionBootCamp()
}