-
Notifications
You must be signed in to change notification settings - Fork 0
/
ScreenIdoso.swift
93 lines (78 loc) · 2.87 KB
/
ScreenIdoso.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
86
87
88
89
90
91
import SwiftUI
struct ScreenIdoso: View {
@State private var isHolding = false
@State private var progress: CGFloat = 0.0
@State private var timer: Timer?
@Binding var remedio: String
@Binding var hora: String
@State var exibirScreen: Binding<Bool>;
var body: some View {
VStack {
Spacer()
// Nome do medicamento - Centralizado
Text(remedio)
.font(.largeTitle)
.fontWeight(.bold)
.foregroundColor(.white)
.multilineTextAlignment(.center) // Centraliza o texto
// Horário - Centralizado
Text("\(hora)h")
.font(.title)
.foregroundColor(.white)
.padding(.bottom, 50)
.multilineTextAlignment(.center) // Centraliza o texto
// Botão com Progress Bar - Centralizado
ZStack {
Circle()
.stroke(lineWidth: 10)
.foregroundColor(.white.opacity(0.3))
Circle()
.trim(from: 0.0, to: progress)
.stroke(style: StrokeStyle(lineWidth: 10, lineCap: .round))
.foregroundColor(.white)
.rotationEffect(.degrees(-90))
.animation(.linear, value: progress) // Animate progress
Text("Segure")
.font(.title)
.foregroundColor(.white)
.onLongPressGesture(
minimumDuration: 3.0,
pressing: { pressing in
if pressing {
startProgress()
} else {
resetProgress()
}
},
perform: {
exibirScreen.wrappedValue = false
}
)
}
.frame(width: 200, height: 200) // Tamanho ajustado para o botão
.padding()
Spacer()
}
.frame(maxWidth: .infinity, maxHeight: .infinity) // Para garantir centralização
.background(Color.pink)
.edgesIgnoringSafeArea(.all)
}
// Função para iniciar o progresso
func startProgress() {
isHolding = true
timer = Timer.scheduledTimer(withTimeInterval: 0.01, repeats: true) { _ in
if self.progress < 1.0 {
self.progress += 0.01 / 3.0 // 3 segundos
} else {
self.timer?.invalidate()
print("Progress completed!")
}
}
}
// Função para resetar o progresso
func resetProgress() {
isHolding = false
timer?.invalidate()
progress = 0.0
}
}