Skip to content

Instantly share code, notes, and snippets.

@amosgyamfi
Created April 19, 2022 20:20
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 amosgyamfi/e8c215de81bc5a48e19a425f18487bcd to your computer and use it in GitHub Desktop.
Save amosgyamfi/e8c215de81bc5a48e19a425f18487bcd to your computer and use it in GitHub Desktop.
//
// Chains.swift
// Stream Spring Demo
//
// Created by Amos
//
import SwiftUI
struct StreamDemo: View {
let letters = Array("Stream")
@State private var enabled = false
@State private var dragAmount = CGSize.zero
var body: some View {
HStack(spacing: 0) {
ForEach(0..<letters.count) { num in
Text(String(letters[num]))
.font(.largeTitle)
.rotationEffect(.degrees(enabled ? 0 : 360), anchor: .bottom)
.offset(dragAmount)
.animation(.interpolatingSpring(stiffness: 170, damping: 15).delay(Double(num) / 20), value: dragAmount)
}
}
.padding()
.gesture(
DragGesture()
.onChanged { dragAmount = $0.translation }
// _ ignore the value coming in this time
.onEnded { _ in
withAnimation{
dragAmount = .zero
enabled.toggle()
}
}
)
}
}
struct StreamDemo_Previews: PreviewProvider {
static var previews: some View {
StreamDemo()
.preferredColorScheme(.dark)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment