SwiftUI的转场动画
记录一下SwiftUI中的一些弹窗动画
import SwiftUI
struct TransitionBootCamp: View {
@State var showView = false
let screenWidth = UIScreen.main.bounds.width
let screenHeight = UIScreen.main.bounds.height
var 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()
}
录屏2024-03-13 00.24.56