withAnimate 中inout
1. **easeInOut 的作用**
2. **其他常见的速度曲线**
withAnimation(.linear(duration: 0.5)) {
showView.toggle()
}3. **自定义动画**
4. **示例代码**
5. **总结**
Last updated
withAnimation(.linear(duration: 0.5)) {
showView.toggle()
}Last updated
withAnimation(.easeIn(duration: 0.5)) {
showView.toggle()
}withAnimation(.easeOut(duration: 0.5)) {
showView.toggle()
}withAnimation(.easeInOut(duration: 0.5)) {
showView.toggle()
}withAnimation(.spring(response: 0.5, dampingFraction: 0.6, blendDuration: 0)) {
showView.toggle()
}withAnimation(.interactiveSpring(response: 0.5, dampingFraction: 0.6, blendDuration: 0)) {
showView.toggle()
}withAnimation(.default) {
showView.toggle()
}import SwiftUI
struct AnimationExampleView: View {
@State private var showView = false
var body: some View {
VStack {
if showView {
Text("Hello, SwiftUI!")
.font(.largeTitle)
.padding()
.background(Color.blue)
.foregroundColor(.white)
.cornerRadius(10)
.transition(.opacity)
}
Button(showView ? "Hide View" : "Show View") {
withAnimation(.easeInOut(duration: 0.5)) {
showView.toggle()
}
}
.padding()
Button("Linear Animation") {
withAnimation(.linear(duration: 0.5)) {
showView.toggle()
}
}
.padding()
Button("Spring Animation") {
withAnimation(.spring(response: 0.5, dampingFraction: 0.6, blendDuration: 0)) {
showView.toggle()
}
}
.padding()
}
}
}