From the course: iPadOS 13 Development Essential Training
Unlock the full course today
Join today to access over 22,600 courses taught by industry experts or purchase this course individually.
Responding to pencil events - iOS Tutorial
From the course: iPadOS 13 Development Essential Training
Responding to pencil events
- [Instructor] So let's say you wanted it to respond when a user changes the tool that they're working with when they're drawing. You can do that through delegation. What we're going to do here is create a new class to represent our delegate object. And that class is also going to be managing the PKCanvasView. So let's select ContentView, and then create a new file with Command + N. And this will be a Cocoa Touch Class, subclass of NSObject. We'll call this CanvasManager, and then hit Next. I'll save it in the default location. And then I'm going to import PencilKit. And then I'm going to specify that this class adopts the PKCanvasViewDelegate protocol. It'll have one property called canvasView, and that's going to be a PKCanvasView. And then in our init method, we'll initialize the CanvasView to a new PKCanvasView. And then I'm going to initialize self with a call to super.init. And after I do that, I can then…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.