Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue with Drawing on PencilKit Canvas After Applying transformGesture and transformEffect #7

Open
rk-helper opened this issue Jun 3, 2024 · 1 comment

Comments

@rk-helper
Copy link

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!

@bobby-kim-km
Copy link

Is it resolved?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants