我将ButtonStyle设置为按钮.在这个按钮上,我设置了一个按下按钮时具有zoom 效果的动画.有没有一种方法可以在动画完成后才执行动作,或者可能延迟执行?现在,当我单击该按钮时,将显示下一个视图,您无法看到该按钮的动画效果.
struct CustomButtonStyle: ButtonStyle {
func makeBody(configuration: Configuration) -> some View {
configuration.label
.foregroundColor(Color.blue)
.padding(.vertical)
.frame(height: 48)
.frame(minWidth: 0, maxWidth: .infinity, alignment: .center)
.background(Color.white)
.cornerRadius(32)
.scaleEffect(configuration.isPressed ? 0.9 : 1.0)
.opacity(configuration.isPressed ? 0.6 : 1.0)
.animation(.easeInOut, value: configuration.isPressed)
}
}
struct TestView: View {
var body: some View {
Button(action: {
// redirect to another view
}, label: {
Text("Test")
}).buttonStyle(CustomButtonStyle())
}
}