I've tried to use mask to make scratch card effect. It can't work. Maybe I use wrong function. Can someone tell me ? Here is the code.
struct ScratchCardView: View {
@State var points: [CGPoint] = []
var body: some View {
ZStack {
Text("Text")
.font(.largeTitle)
GeometryReader(content: { geometry in
Rectangle()
.foregroundColor(.blue)
.mask(MaskView(in: CGRect(origin: .zero, size: geometry.size)))
.gesture(
DragGesture()
.onChanged { value in
points.append(value.location)
}
)
})
}
}
func MaskView(in rect: CGRect) -> some View {
var path = Rectangle().path(in: rect)
for point in points {
path.addPath(Circle().path(in: CGRect(origin: point, size: CGSize(width: 30, height: 30)))
)
}
return path.fill(style: FillStyle(eoFill: true))
}
}