Skip to content

Instantly share code, notes, and snippets.

@beekhof
Created July 30, 2020 07:59
Show Gist options
  • Save beekhof/48fd57058ccb47210a2833b9b976d06b to your computer and use it in GitHub Desktop.
Save beekhof/48fd57058ccb47210a2833b9b976d06b to your computer and use it in GitHub Desktop.
//
// Taby.swift
//
import SwiftUI
import PencilKit
import Foundation
import SwiftUI
import PencilKit
import VisionKit
import Vision
struct TabyCanvasView: UIViewRepresentable {
let canvas = PKCanvasView()
@Environment(\.undoManager) var undoManager
func makeUIView(context: Context) -> PKCanvasView {
canvas.isOpaque = false
canvas.backgroundColor = UIColor.red
canvas.drawingPolicy = .anyInput
return canvas
}
func updateUIView(_ uiView: PKCanvasView, context: Context) {
uiView.delegate = context.coordinator
context.coordinator.toolPicker.addObserver(uiView)
context.coordinator.toolPicker.setVisible(true, forFirstResponder: uiView)
}
func makeCoordinator() -> TabyCoordinator {
return TabyCanvasView.TabyCoordinator(self)
}
class TabyCoordinator: NSObject, PKCanvasViewDelegate {
var toolPicker = PKToolPicker()
var parent: TabyCanvasView
init(_ uiView: TabyCanvasView) {
self.parent = uiView
}
func canvasViewDidBeginUsingTool(_ canvasView: PKCanvasView) {
}
func canvasViewDidEndUsingTool(_ canvasView: PKCanvasView) {
}
func canvasViewDrawingDidChange(_ canvasView: PKCanvasView) {
}
func canvasViewDidFinishRendering(_ canvasView: PKCanvasView) {
}
}
}
struct Taby: View {
let placement: ToolbarItemPlacement = .destructiveAction
var body: some View {
VStack {
VStack() {
Text("Hello, World!")
Button("Button 1") {
print("Clicked 1")
}
Button("Button 2") {
print("Clicked 2")
}
Button("Button 3") {
print("Clicked 3")
}
}
ScrollView {
TabyCanvasView()
.frame(width: /*@START_MENU_TOKEN@*/100/*@END_MENU_TOKEN@*/, height: 2000, alignment: /*@START_MENU_TOKEN@*/.center/*@END_MENU_TOKEN@*/)
}
}
}
}
struct Taby_Previews: PreviewProvider {
static var previews: some View {
Taby()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment