-
Notifications
You must be signed in to change notification settings - Fork 43
/
StifnessDamping.swift
60 lines (51 loc) · 1.81 KB
/
StifnessDamping.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
//
// StiffnessDamping.swift
// Stiffness and damping variations: Stiff, gentle, wobble, no wobble
//
// Created by Amos from getstream.io
//
import SwiftUI
struct StiffnessDamping: View {
@State private var moving = false
var body: some View {
VStack(alignment: .leading) {
// Ball 1
HStack(spacing: 50) {
Text("Stiff: ")
Image("ball")
.offset(x: moving ? 0 : 100)
.animation(.interpolatingSpring(stiffness: 210, damping: 20).repeatForever(autoreverses: true), value: moving)
}
// Ball 2
HStack(spacing: 50) {
Text("Gentle: ")
Image("ball")
.offset(x: moving ? 0 : 100)
.animation(.interpolatingSpring(stiffness: 120, damping: 14).repeatForever(autoreverses: true), value: moving)
}
// Ball 3
HStack(spacing: 50) {
Text("Wobble: ")
Image("ball")
.offset(x: moving ? 0 : 100)
.animation(.interpolatingSpring(stiffness: 180, damping: 12).repeatForever(autoreverses: true), value: moving)
}
// Ball 4
HStack(spacing: 50) {
Text("No wobble: ")
Image("ball")
.offset(x: moving ? 0 : 100)
.animation(.interpolatingSpring(stiffness: 170, damping: 26).repeatForever(autoreverses: false), value: moving)
}
} // All balls
.onAppear{
moving.toggle()
}
}
}
struct StiffnessDamping_Previews: PreviewProvider {
static var previews: some View {
StiffnessDamping()
.preferredColorScheme(.dark)
}
}