Created
March 18, 2022 11:38
-
-
Save amosgyamfi/fa899f1026ed71db52c83da5afb69ecf to your computer and use it in GitHub Desktop.
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
// | |
// 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