Created
March 2, 2024 15:47
-
-
Save DarrenHurst/109aa51cb45c086458e9de4211d07e7f to your computer and use it in GitHub Desktop.
Bunny Hop 1
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
import Foundation | |
import SwiftUI | |
import PencilKit | |
struct DrawingView: View { | |
private var canvasView = PKCanvasView() | |
var body: some View { | |
MyCanvas(canvasView: canvasView) | |
} | |
} | |
struct MyCanvas: UIViewRepresentable { | |
var canvasView: PKCanvasView | |
let picker = PKToolPicker.init() | |
func makeUIView(context: Context) -> PKCanvasView { | |
self.canvasView.tool = PKInkingTool(.pen, color: .black, width: 15) | |
self.canvasView.becomeFirstResponder() | |
self.canvasView.backgroundColor = .clear | |
return canvasView | |
} | |
func updateUIView(_ uiView: PKCanvasView, context: Context) { | |
picker.addObserver(canvasView) | |
picker.setVisible(true, forFirstResponder: uiView) | |
DispatchQueue.main.async { | |
uiView.becomeFirstResponder() | |
} | |
} | |
} | |
struct WonderFile001: View { | |
@State var animate: Bool = false | |
func earShape() -> some View { | |
return ZStack { | |
GeometryReader { r in | |
Image("bunny", bundle: Bundle.module) | |
.resizable() | |
.frame(width: r.size.width, height: r.size.height) | |
.scaledToFit() | |
DrawingView() | |
.frame(width: r.size.width, height: r.size.height) | |
} | |
}.offset(y:-40) | |
} | |
var body: some View { | |
VStack { | |
ZStack { | |
earShape().ignoresSafeArea() | |
} | |
} | |
.background(Config().background) | |
.background(Rectangle()) | |
} | |
} | |
struct WonderFile001Preview: PreviewProvider { | |
static var previews: some View { | |
WonderFile001() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment