-
Notifications
You must be signed in to change notification settings - Fork 43
/
InteractiveSpring.swift
53 lines (41 loc) · 1.49 KB
/
InteractiveSpring.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
//
// InteractiveSpring.swift
// hamburger_to_close
// Using an interactive spring. An interactive spring with no parameters.
// This creates a spring animation with a high stiffness and a low response. It creates a spring animation that is less snappy:
// Created by Amos from getstream.io
//
import SwiftUI
struct InteractiveSpring: View {
@State private var isRotating = false
@State private var isHidden = false
var body: some View {
VStack(spacing: 14){
Rectangle() // top
.frame(width: 64, height: 10)
.cornerRadius(4)
.rotationEffect(.degrees(isRotating ? 48 : 0), anchor: .leading)
Rectangle() // middle
.frame(width: 64, height: 10)
.cornerRadius(4)
.scaleEffect(isHidden ? 0 : 1, anchor: isHidden ? .trailing: .leading)
.opacity(isHidden ? 0 : 1)
Rectangle() // bottom
.frame(width: 64, height: 10)
.cornerRadius(4)
.rotationEffect(.degrees(isRotating ? -48 : 0), anchor: .leading)
}
.onTapGesture {
withAnimation(.interactiveSpring()){
isRotating.toggle()
isHidden.toggle()
}
}
}
}
struct InteractiveSpring_Previews: PreviewProvider {
static var previews: some View {
InteractiveSpring()
.preferredColorScheme(.dark)
}
}