Skip to content

Instantly share code, notes, and snippets.

@amosgyamfi
Created March 18, 2022 11:38
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save amosgyamfi/fa899f1026ed71db52c83da5afb69ecf to your computer and use it in GitHub Desktop.
Save amosgyamfi/fa899f1026ed71db52c83da5afb69ecf to your computer and use it in GitHub Desktop.
//
// Chains.swift
// HundredDaysOfSwiftUI
//
// Created by Amos
//
import SwiftUI
struct Chains: View {
let letters = Array("πŸ”—πŸ”—πŸ”—πŸ”—πŸ”—πŸ”—πŸ”—πŸ”—πŸ”—πŸ”—πŸ”—πŸ”—πŸ”—πŸ”—πŸ”—πŸ”—πŸ”—πŸ”—πŸ”—πŸ”—πŸ”—πŸ”—πŸ”—πŸ”—πŸ”—")
@State private var enabled = false
@State private var dragAmount = CGSize.zero
var body: some View {
VStack(spacing: 0) {
ForEach(0..<letters.count) { num in
Text(String(letters[num]))
.padding(-10)
.font(.largeTitle)
.rotationEffect(.degrees(enabled ? 0 : 360), anchor: .bottom)
.offset(dragAmount)
.animation(.interpolatingSpring(stiffness: 170, damping: 5).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 Chains_Previews: PreviewProvider {
static var previews: some View {
Chains()
.preferredColorScheme(.dark)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment