-
Notifications
You must be signed in to change notification settings - Fork 644
Expand file tree
/
Copy pathLineShape.swift
More file actions
36 lines (32 loc) · 1.29 KB
/
LineShape.swift
File metadata and controls
36 lines (32 loc) · 1.29 KB
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
import SwiftUI
struct LineShape: Shape, Animatable {
var data: [Double]
var animatableData: AnimatableVector {
get { AnimatableVector(values: data) }
set { data = newValue.values }
}
func path(in rect: CGRect) -> Path {
let path = Path.quadCurvedPathWithPoints(points: data, step: CGPoint(x: 1.0, y: 1.0))
return path
}
}
struct LineShape_Previews: PreviewProvider {
static var previews: some View {
Group {
GeometryReader { geometry in
LineShape(data: [0, 0.5, 0.8, 0.6, 1])
.transform(CGAffineTransform(scaleX: geometry.size.width / 4.0, y: geometry.size.height))
.stroke(Color.red)
.rotationEffect(.degrees(180), anchor: .center)
.rotation3DEffect(.degrees(180), axis: (x: 0, y: 1, z: 0))
}
GeometryReader { geometry in
LineShape(data: [0, -0.5, 0.8, -0.6, 1])
.transform(CGAffineTransform(scaleX: geometry.size.width / 4.0, y: geometry.size.height / 1.6))
.stroke(Color.blue)
.rotationEffect(.degrees(180), anchor: .center)
.rotation3DEffect(.degrees(180), axis: (x: 0, y: 1, z: 0))
}
}
}
}