Junior — Senior
Smooth zoom transition when pressing the button
livecode
Task condition
It is necessary to add animation to the user style of the button so that its scale change occurs smoothly, not with sharp jumps.
struct AppButtonStyle: ButtonStyle {
func body(_ ctx: Configuration) -> some View {
Text(ctx.label)
.scaleEffect(ctx.isPressed ? 0.5 : 1.0)
.animation(.easeInOut(duration: 0.2), value: ctx.isPressed)
}
}
This example uses SwiftUI. When pressed (ctx.isPressed == true), the button will shrink to 50% of its original size, and when released, it will return to normal size. The smoothness is achieved by applying an easeInOut animation with a duration of 0.2 seconds.