-
Notifications
You must be signed in to change notification settings - Fork 43
/
BouncyHamburger.swift
52 lines (41 loc) · 1.43 KB
/
BouncyHamburger.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
//
// BouncyHamburger.swift
// Hamburger to Close
//
// Learning SwiftUI Spring Animations: The Basics and Beyond
// Create a bouncy hamburger menu to close icon transition
// Created by Amos from getstream.io
import SwiftUI
struct BouncyHamburger: 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(.interpolatingSpring(stiffness: 300, damping: 15)){
isRotating.toggle()
isHidden.toggle()
}
}
}
}
struct BouncyHamburger_Previews: PreviewProvider {
static var previews: some View {
BouncyHamburger()
.preferredColorScheme(.dark)
}
}