gadirom / transformgesture Goto Github PK
View Code? Open in Web Editor NEWHandle two finger transformation gesture in SwiftUI and Metal views
Handle two finger transformation gesture in SwiftUI and Metal views
Hi,
Iām experiencing an issue when using the TransformGesture package with a PencilKit canvas in SwiftUI. My goal is to allow for complex gestures (pinching, rotating, and dragging) while still being able to draw on the canvas. However, after applying the transformGesture and transformEffect modifiers, Iām unable to draw on the PencilKit canvas.
Here is a snippet of my code:
struct ContentView: View {
@StateObject private var transform = TouchTransform()
@State private var canvasView = PKCanvasView()
var body: some View {
VStack {
PencilKitCanvasView(canvasView: $canvasView)
.transformEffect(transform)
.transformGesture(transform: transform,
draggingDisabled: false,
active: true)
.edgesIgnoringSafeArea(.all)
}
}
}
struct PencilKitCanvasView: UIViewRepresentable {
@Binding var canvasView: PKCanvasView
func makeUIView(context: Context) -> PKCanvasView {
canvasView.drawingPolicy = .anyInput
return canvasView
}
func updateUIView(_ uiView: PKCanvasView, context: Context) {
// Update the view if needed
}
}
With this setup, the gestures work fine, but I can no longer draw on the canvas. It seems like the gesture handling might be interfering with the drawing capability of PencilKit.
Questions:
1. Is there a way to use TransformGesture with PencilKit so that both gesture recognition and drawing functionality can coexist?
2. Are there specific configurations or additional steps required to achieve this?
Any help or suggestions would be greatly appreciated.
Thank you!
Hey, this looks really cool. Have you picked an open source license for this?
Thank you so much for making this package. It works well, for most cases, however I found that if the view is inside a ForEach, it does not. Any ideas for a workaround / fix?
ForEach(viewDescriptors) { desc in
customView(desc)
.transformEffect(transform)
.transformGesture(transform: transform, draggingDisabled: false, active: true) { _ in
}
}
This is also observed when there is a single element in viewDescriptors.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
š Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ššš
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ā¤ļø Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.