-
Notifications
You must be signed in to change notification settings - Fork 43
/
Spring.swift
53 lines (41 loc) · 1.38 KB
/
Spring.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
//
// Spring.swift
// hamburger_to_close
// Using the default spring. A spring with no parameters.
// .spring() applies gentle and sensible spring-feel to the object you want to animate
// Created by Amos from getstream.io
//
import SwiftUI
struct Spring: 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(.spring()){
isRotating.toggle()
isHidden.toggle()
}
}
}
}
struct Spring_Previews: PreviewProvider {
static var previews: some View {
Spring()
.preferredColorScheme(.dark)
}
}