Created
December 12, 2023 19:08
-
-
Save SLIB53/43761b997871bfc610b7264ce7374bec to your computer and use it in GitHub Desktop.
PencilKit sample
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// ContentView.swift | |
// Drawing | |
// | |
// Created by Akil Krishnan on 12/5/23. | |
// | |
import SwiftUI | |
import PencilKit | |
struct ContentView: View { | |
var body: some View { | |
PencilView() | |
} | |
} | |
struct PencilView: UIViewRepresentable { | |
@State var canvasView = PKCanvasView() | |
@State var toolPicker = PKToolPicker() | |
func makeUIView(context: Context) -> PKCanvasView { | |
canvasView.contentSize = CGSize( | |
width: UIScreen.main.bounds.width, | |
height: UIScreen.main.bounds.height | |
) | |
canvasView.backgroundColor = .clear | |
canvasView.isScrollEnabled = false | |
toolPicker.setVisible(true, forFirstResponder: canvasView) | |
toolPicker.addObserver(canvasView) | |
canvasView.becomeFirstResponder() | |
return canvasView | |
} | |
func updateUIView(_ uiView: PKCanvasView, context: Context) {} | |
} | |
#Preview { | |
ContentView() | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// DrawingApp.swift | |
// Drawing | |
// | |
// Created by Akil Krishnan on 12/5/23. | |
// | |
import SwiftUI | |
@main | |
struct DrawingApp: App { | |
var body: some Scene { | |
WindowGroup { | |
ContentView() | |
.statusBarHidden(true) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment