-
-
Save OgreSwamp/6e6423d6ef2d26425e3f993042ac208d to your computer and use it in GitHub Desktop.
Slider Animation Playground
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import SwiftUI | |
import PlaygroundSupport | |
struct SliderTest: View { | |
@State private var sliderValue = 0.0 | |
let maxValue = 30.0 | |
var body: some View { | |
VStack(spacing: 10) { | |
Slider(value: $sliderValue, in: 0...maxValue) | |
Button("Animate Slider") { | |
withAnimation(.linear(duration: maxValue-sliderValue)) { | |
sliderValue = maxValue | |
} | |
} | |
Button("Reset to Random") { | |
sliderValue = Double.random(in: 0..<maxValue) | |
} | |
Button("Reset") { | |
sliderValue = 0 | |
} | |
} | |
} | |
} | |
PlaygroundPage.current.setLiveView( | |
SliderTest() | |
.frame(width: 200, height: 200, alignment: .center) | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment