A view that captures Apple Pencil input and displays the rendered results in an iOS app.


class PKCanvasView : UIScrollView


A PKCanvasView object captures content drawn using Apple Pencil or the user’s finger and displays it in your app. Add a canvas view to your interface when you want to capture or display user-drawn content. The canvas view handles all of the touch events and data coming from Apple Pencil, and renders that information using the tool you specify. The canvas stores the captured input in a PKDrawingReference object.

PKCanvasView is a scroll view, so you can make the drawable area bigger than the canvas view’s frame rectangle. To do that, set the inherited contentSize property to the size you want. The canvas view automatically scales its underlying content to match the size you specify. Users scroll around the canvas using a two-finger pan gesture. (If the allowsFingerDrawing property is false, users scroll with only one finger.)

A canvas view conforms to the PKToolPickerObserver protocol, so you can add it as an observer of the window’s tool picker. The tool picker displays a floating palette of tools for the user to choose from. As the user interacts with items in the palette, the canvas automatically updates its drawing environment accordingly.


Responding to Drawing-Related Changes

var delegate: PKCanvasViewDelegate?

The object you use to respond to changes in the drawn content or in the selected tool.

protocol PKCanvasViewDelegate

Methods you use to track editing-related changes in a canvas view.

Configuring the Drawing Environment

var tool: PKTool

The currently selected tool for drawing.

var isRulerActive: Bool

A Boolean value that indicates whether a ruler view is currently visible on the canvas.

var allowsFingerDrawing: Bool

A Boolean value that indicates whether the canvas accepts input from the user’s finger in addition to Apple Pencil.

Getting the Drawing Gesture Recognizer

var drawingGestureRecognizer: UIGestureRecognizer

The gesture recognizer that the canvas uses to track touch events.

Getting the Captured Data

var drawing: PKDrawing

The data object that the canvas uses to store drawn content.

See Also


Drawing With PencilKit

Add expressive, low-latency drawing to your application with PencilKit.

struct PKDrawing

An opaque data object that contains the drawing information captured by a canvas view.

class PKDrawingReference

An opaque data object that contains the drawing information captured by a canvas view.