-
Notifications
You must be signed in to change notification settings - Fork 43
/
ChainedSpring.swift
86 lines (72 loc) · 3.58 KB
/
ChainedSpring.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
//
// ChainedSpring.swift
// Learning SwiftUI Spring Animations: The Basics and Beyond
// Hint: Apply a different delay to each oval the achieve this spring effect.
//
// Created by Amos from getstream.io
//
import SwiftUI
struct ChainedSpring: View {
@State private var moving = false
var body: some View {
ZStack{
Circle() // One
.stroke(lineWidth: 5)
.frame(width: 20, height: 20)
.rotation3DEffect(.degrees(75), axis: (x: 1, y: 0, z: 0))
.offset(y: moving ? 150 : -180)
.animation(.interpolatingSpring(stiffness: 100, damping: 5).repeatForever(autoreverses: true), value: moving)
Circle() // Two
.stroke(lineWidth: 5)
.frame(width: 50, height: 50)
.rotation3DEffect(.degrees(75), axis: (x: 1, y: 0, z: 0))
.offset(y: moving ? 150 : -180)
.animation(.interpolatingSpring(stiffness: 100, damping: 5).repeatForever(autoreverses: true).delay(0.05), value: moving)
Circle() // Three
.stroke(lineWidth: 5)
.frame(width: 80, height: 80)
.rotation3DEffect(.degrees(75), axis: (x: 1, y: 0, z: 0))
.offset(y: moving ? 150 : -180)
.animation(.interpolatingSpring(stiffness: 100, damping: 5).repeatForever(autoreverses: true).delay(0.1), value: moving)
Circle() // Four
.stroke(lineWidth: 5)
.frame(width: 110, height: 110)
.rotation3DEffect(.degrees(75), axis: (x: 1, y: 0, z: 0))
.offset(y: moving ? 150 : -180)
.animation(.interpolatingSpring(stiffness: 100, damping: 5).repeatForever(autoreverses: true).delay(0.15), value: moving)
Circle() // Five
.stroke(lineWidth: 5)
.frame(width: 140, height: 140)
.rotation3DEffect(.degrees(75), axis: (x: 1, y: 0, z: 0))
.offset(y: moving ? 150 : -180)
.animation(.interpolatingSpring(stiffness: 100, damping: 5).repeatForever(autoreverses: true).delay(0.2), value: moving)
Circle() // Six
.stroke(lineWidth: 5)
.frame(width: 170, height: 170)
.rotation3DEffect(.degrees(75), axis: (x: 1, y: 0, z: 0))
.offset(y: moving ? 150 : -180)
.animation(.interpolatingSpring(stiffness: 100, damping: 5).repeatForever(autoreverses: true).delay(0.25), value: moving)
Circle() // Seven
.stroke(lineWidth: 5)
.frame(width: 200, height: 200)
.rotation3DEffect(.degrees(75), axis: (x: 1, y: 0, z: 0))
.offset(y: moving ? 150 : -180)
.animation(.interpolatingSpring(stiffness: 100, damping: 5).repeatForever(autoreverses: true).delay(0.3), value: moving)
Circle() // Eight
.stroke(lineWidth: 5)
.frame(width: 230, height: 230)
.rotation3DEffect(.degrees(75), axis: (x: 1, y: 0, z: 0))
.offset(y: moving ? 150 : -180)
.animation(.interpolatingSpring(stiffness: 100, damping: 5).repeatForever(autoreverses: true).delay(0.35), value: moving)
}
.onAppear{
moving.toggle()
}
}
}
struct ChainedSpring_Previews: PreviewProvider {
static var previews: some View {
ChainedSpring()
.preferredColorScheme(.dark)
}
}