-
Notifications
You must be signed in to change notification settings - Fork 263
/
Copy pathSlideToCancelWithScale.swift
85 lines (71 loc) · 3.17 KB
/
SlideToCancelWithScale.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
//
// SlideToCancelWithScale.swift
import SwiftUI
struct SlideToCancelWithScale: View {
@State private var counter: Int = 0
private let timer = Timer.publish(every: 1, on: .main, in: .common).autoconnect()
@State private var isSliding: Bool = false
@State private var isShimmering = false
let letters = Array("Slide to cancel")
let slideGently = Animation.easeOut(duration: 0.5).delay(2).repeatForever(autoreverses: false).delay(-0.67)
var body: some View {
VStack {
HStack(alignment: .bottom) {
HStack {
HStack{
Image(systemName: "mic.fill")
.font(.title)
.bold()
.opacity(isSliding ? 0 : 1)
.foregroundColor(Color(.systemRed))
.animation(.easeInOut(duration: 0.5).repeatForever(autoreverses: true), value: isSliding)
Text("\(counter)")
.monospacedDigit()
.onReceive(timer) { _ in
counter += 1
}
}
Spacer()
HStack {
HStack(spacing: 0) {
ForEach(0..<letters.count, id: \.self) { slide in
Text(String(letters[slide]))
.scaleEffect(isSliding ? 0.25 : 1)
.opacity(isSliding ? 0 : 1)
.offset(x: isSliding ? -25 : 1)
.animation(.easeInOut(duration: 0.5).delay(2).repeatForever(autoreverses: false).delay(Double(-slide) / 20), value: isSliding)
}
}
Image(systemName: "chevron.left")
.font(.subheadline)
.fontWeight(.bold)
.scaleEffect(isSliding ? 0.25 : 1)
.opacity(isSliding ? 0 : 1)
.offset(x: isSliding ? -50 : 1)
.animation(slideGently, value: isSliding)
}
Spacer()
Image(systemName: "mic")
.font(.title)
.bold()
.foregroundColor(.blue)
}
.padding(EdgeInsets(top: 16, leading: 32, bottom: 16, trailing: 32))
.background(Color(.systemGray4))
.cornerRadius(32)
LockAnimationView()
}
.onAppear {
isShimmering.toggle()
isSliding = true
}
}
.padding()
}
}
struct SlideToCancelWithScale_Previews: PreviewProvider {
static var previews: some View {
SlideToCancelWithScale()
.preferredColorScheme(.dark)
}
}