-
Notifications
You must be signed in to change notification settings - Fork 43
/
NotificationAnimation.swift
64 lines (49 loc) · 2.01 KB
/
NotificationAnimation.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
// NotificationAnimation.swift
// Bell Notification Animation
// Learning SwiftUI Spring Animations: The Basics and Beyond
//
// Created by Amos from getstream.io
//
//
import SwiftUI
struct NotificationAnimation: View {
@State private var bellRotating = -45
@State private var clapperMoving = false
var body: some View {
VStack {
Text("Enable Notifications")
.font(.title)
Spacer()
ZStack {
VStack(spacing: 25) {
Circle() // Hinge
.frame(width: 10, height: 10)
.foregroundColor(Color(.systemGray2))
Circle() // Clapper
.frame(width: 16, height: 16, alignment: .topLeading)
.rotationEffect(.degrees(0), anchor: clapperMoving ? .leading : .topTrailing)
.offset(x: CGFloat(clapperMoving ? -10 : 25), y: CGFloat(clapperMoving ? -4 : 2))
.animation(.interpolatingSpring(stiffness: 170, damping: 5).repeatForever(autoreverses: false), value: clapperMoving)
}
.hueRotation(.degrees(200))
Image("bell") // Body
.shadow(radius: 4 )
.rotationEffect(.degrees( Double(bellRotating)), anchor: .top)
.hueRotation(.degrees(200))
.animation(.interpolatingSpring(stiffness: 170, damping: 5).repeatForever(autoreverses: false), value: bellRotating)
}
.scaleEffect(2)
.onAppear() {
bellRotating = 15
clapperMoving.toggle()
}
Spacer()
} // Container for all views
}
}
struct NotificationAnimation_Previews: PreviewProvider {
static var previews: some View {
NotificationAnimation()
.preferredColorScheme(.dark)
}
}