Structure

PKDrawing

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

Declaration

struct PKDrawing

Overview

A PKDrawing object stores the user-drawn content from a PKCanvasView object. You use drawing objects to store the data associated with your user’s drawings. You can save this data with the rest of your app’s content, and you can use that saved data to create a new drawing object later. You can also generate an image based on the drawn content.

Topics

Creating a Drawing Object

init(data: Data)

Creates a drawing object and populates it with previously drawn content.

init()

Creates a drawing object with no initial content.

Getting the Canvas Bounds

var bounds: CGRect

The smallest rectangle that represents the content's bounds, taking into account line widths of that content.

Generating an Image

func image(from: CGRect, scale: CGFloat) -> UIImage

Returns an image object containing the specified portion of the drawing.

func image(from: CGRect, scale: CGFloat) -> NSImage

Returns an image object containing the specified portion of the drawing.

Getting the Drawing Data

func dataRepresentation() -> Data

Returns an opaque representation of the rendered content.

Modifying the Drawing

func append(PKDrawing)

Appends the contents of the specified drawing object to the current drawing object.

func appending(PKDrawing) -> PKDrawing

Returns a copy of the current drawing object and appends the specified content to it.

Comparing Drawing Objects

static func != (PKDrawing, PKDrawing) -> Bool

Returns a Boolean value indicating whether the two drawing objects are equivalent.

Encoding the Drawing Object

Relationships

See Also

Canvas

Drawing With PencilKit

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

class PKCanvasView

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

Beta
class PKDrawingReference

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

Beta

Beta Software

This documentation contains preliminary information about an API or technology in development. This information is subject to change, and software implemented according to this documentation should be tested with final operating system software.

Learn more about using Apple's beta software