-
Notifications
You must be signed in to change notification settings - Fork 0
/
CircleAnimation.swift
97 lines (90 loc) · 3.33 KB
/
CircleAnimation.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
92
93
94
95
96
97
import SwiftUI
struct CircleAnimation: View {
@State private var size = CGFloat(100)
@State private var trim = CGFloat(0.75)
@State private var dashSpacing = CGFloat(5)
@State private var dashWidth = CGFloat(15)
@State private var lineWidth = CGFloat(15)
@State private var lineCap = CGLineCap.round
@State private var lineColor = Color.primary
var body: some View {
ScrollView {
VStack {
ZStack {
Circle()
.trim(from: 0, to: trim)
.rotation(.degrees(-90))
.stroke(lineColor, style: strokeStyle)
.frame(width: size, height: size)
.padding()
Text("\(size.formatted())")
.font(.system(size: size / 5))
.bold()
.background(.red)
}
Slider(
value: $size,
in: 50...300,
step: 15
).frame(width: 150)
Text("Size: (\(size.formatted()))").font(.headline)
Slider(
value: $trim,
in: 0...1,
step: 0.01
)
.accentColor(trim > 0.5 ? .orange : .blue)
.frame(width: 150)
Text("Trim: (\(trim.formatted()))").font(.headline)
Stepper("Trim (\(trim.formatted())): ",
value: $trim,
in: 0...1,
step: 0.1
)
Stepper("Dash Spacing (\(dashSpacing.formatted())): ",
value: $dashSpacing,
in: 0...100,
step: 1
)
Stepper("Dash Width (\(dashWidth.formatted())): ",
value: $dashWidth,
in: 0...100,
step: 1
)
Stepper("Line Width (\(lineWidth.formatted())): ",
value: $lineWidth,
in: 0...100,
step: 5
)
ColorPicker("Line color", selection: $lineColor)
}
.animation(
.spring(
response: 1.5,
dampingFraction: 0.5,
blendDuration: 0.5
), value: size)
.animation(.spring(), value: trim)
.animation(.easeIn(duration: 0.1), value: lineWidth)
.padding()
}
}
private var strokeStyle: StrokeStyle {
StrokeStyle(
lineWidth: lineWidth,
lineCap: .butt, // .butt, .round, .square
lineJoin: .miter,
miterLimit: 0,
dash: [dashWidth, dashSpacing], // largura, espaçamento
dashPhase: 0
)
}
}
struct CircleAnimation_Previews: PreviewProvider {
static var previews: some View {
CircleAnimation().preferredColorScheme(.light)
CircleAnimation().preferredColorScheme(.light).previewInterfaceOrientation(.landscapeRight)
CircleAnimation().preferredColorScheme(.dark)
CircleAnimation().preferredColorScheme(.dark).environment(\.sizeCategory, .accessibilityLarge)
}
}