PencilKit PKCanvasView tiling?

Forgive me if this is the wrong place for this question, I don't see PencilKit anyhere on the forum listings and I don't really see anything that it approximates either. Since I'm hoping to use it along with MapKit, I figure this might be a reasonable place to start!


I'm trying to figure out how to layer a PKCanvasView on top of a MKMapView such that I can draw on the map. That's the long game. But I've run into some limitations and not certain how to approach them. Mainly, I am not sure how to, or if it's even possible to, make PKCanvasView "wrap around" like MKMapView does. PKCanvasView is a UIScrollView, and the way folks seem to do that is using the "8 1 2 3 ... 8 1" method. Doing that with a bunch of PKCanvasViews to simulate wrapping around seems like a pain, but also seems fairly reasonable at the same time. However, I can't seem to make pencil strokes cross into neighboring PKCanvasViews. As a quick experiment I made a VStack (swiftui) with 2 PKCanvasView UIViewRepresentables which I can draw on separately, but when I get to the edge of the canvas, the line stops. When I cross back without lifting the pencil, the line resumes. This also happens on the other view. By default there seems to be a gap between the canvases so I thought maybe that was a problem, but eliminating the gap didn't seem to help.


Has anyone tried to do this tiling of PKCanvasViews and succeeded? Or even just implemented a "draw on top of a map with the apple pencil" and could share some pointers or maybe even code?


The WWDC19 221 slides have "tiling" on the tagcloud slide, but searching isn't coming up with much, and the documentation doesn't mention anything about it.


I have a feeling this is not currently possible (and may never be possible with PencilKit) so I'll probably have to roll my own drawing interface, but I'd like to at least give this a good heave-ho before I give up on it.


Thanks!

Replies

The "tiling" word from that slide mentions how they internally implemented PKCanvasView. If you "Debug View Hierarchy" in Xcode, you'll see that there is a tiling view among other subviews of the PKCanvasView.



Tiling is not a feature that's available to developers directly. I believe there is a chance to achieve this by hacking responder chain, so while stroking with Pencil check if it's off the current canvas bounds, if so, pass touch events to the next canvas.

Thank you for the answer! Debug View Hierarchy is not something I'd seen before (I'm *very* new to doing any sort of iOS development) so thanks for that tip. It will be very useful in the future.


As far as the responder chain stuff, yea, I was thinking it might be something like that. The canvas is set to only handle touch events when it's the primary responder, and there can only be one primary responder. So some sort of "detect when it's on a different canvas and make that one the primary responder is your suggestion? I was thinking the same thing. I don't know how to do that yet but I will keep that in mind as I learn more about how all of this stuff comes together.


Thanks again for your reply!