Skip to content

Instantly share code, notes, and snippets.

@OgreSwamp
Created August 31, 2022 12:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save OgreSwamp/6e6423d6ef2d26425e3f993042ac208d to your computer and use it in GitHub Desktop.
Save OgreSwamp/6e6423d6ef2d26425e3f993042ac208d to your computer and use it in GitHub Desktop.
Slider Animation Playground
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