PSPDFDrawView


@interface PSPDFDrawView
    : UIView <PSPDFAnnotationViewProtocol, PSPDFOverridable>

PSPDFDrawView allows drawing or erasing on top of a PSPDFPageView and handles new annotation creation.

The class holds an array of PSPDFDrawLayer objects that will later be converted into PDF annotations.

The conversion from draw view to annotation isn’t necessary 1:1. Some draw actions can be left out (for instance if there are validation errors like too few points for the annotation).

Unless otherwise noted, boxed points need to be of type PSPDFDrawingPoint.

  • Current annotation type that is being created/edited.

    Declaration

    Objective-C

    @property (assign, readwrite, nonatomic) PSPDFAnnotationType annotationType;

    Swift

    var annotationType: PSPDFAnnotationType { get set }
  • The selected tool variant. Applied to new annotations.

    Declaration

    Objective-C

    @property (assign, readwrite, nonatomic, nullable) NSString *annotationVariant;

    Swift

    var annotationVariant: String? { get set }
  • Determines what effect touch events have. Defaults to PSPDFDrawViewInputModeDraw. PSPDFDrawViewInputModeErase only affects Ink annotations.

    Declaration

    Objective-C

    @property (assign, readwrite, nonatomic) PSPDFDrawViewInputMode inputMode;

    Swift

    var inputMode: PSPDFDrawViewInputMode { get set }
  • The touch types that should be used for drawing. Array of UITouchType wrapped in NSNumber. The defaults are UITouchTypeDirect and UITouchTypeStylus.

    Declaration

    Objective-C

    @property (readwrite, copy, nonatomic)
        NSArray<NSNumber *> *_Nonnull allowedTouchTypes;

    Swift

    var allowedTouchTypes: [NSNumber] { get set }
  • Current active draw layer. This action is currently receiving input. Set only during input while in PSPDFDrawViewInputModeDraw input mode.

    Declaration

    Objective-C

    @property (readonly, nonatomic, nullable) PSPDFDrawLayer *currentDrawLayer;

    Swift

    var currentDrawLayer: PSPDFDrawLayer? { get }
  • Array of PSPDFDrawLayer objects that have been created during the draw view session or imported using updateActionsForAnnotations:. - note: Allows KVO observation.

    Declaration

    Objective-C

    @property (readonly, nonatomic) NSArray<PSPDFDrawLayer *> *_Nonnull drawLayers;

    Swift

    var drawLayers: [PSPDFDrawLayer] { get }
  • Clear all actions. Registers as a single undo action, if undo is supported.

    Declaration

    Objective-C

    - (void)clearAllLayers;

    Swift

    func clearAllLayers()
  • The gesture recognizer used to detect drawings.

    Setting its allowedTouchTypes property can be used to limit the allowed types however the draw layer may still ignore touches even if they are in the list of allowed types. This is used for Apple Pencil support.

    See

    -[PSPDFAnnotationStateManager stylusMode]

    Declaration

    Objective-C

    @property (readonly, nonatomic)
        UIGestureRecognizer *_Nonnull drawGestureRecognizer;

    Swift

    var drawGestureRecognizer: UIGestureRecognizer { get }
  • All annotations currently managed by the draw view.

    Declaration

    Objective-C

    @property (readonly, nonatomic)
        NSArray<__kindof PSPDFAnnotation *> *_Nonnull annotations;

    Swift

    var annotations: [PSPDFAnnotation] { get }
  • Defines how ink annotations are created.

    See

    PSPDFConfiguration for details.

    Note

    The default value for this setting is read from the current active PSPDFConfiguration object.

    Declaration

    Objective-C

    @property (assign, readwrite, nonatomic) PSPDFDrawCreateMode drawCreateMode;

    Swift

    var drawCreateMode: PSPDFDrawCreateMode { get set }
  • Enables natural drawing via tracking the pressure sensitivity of the points.

    See

    PSPDFConfiguration for details.

    Note

    The default value for this setting is read from the current active PSPDFConfiguration object.

    Declaration

    Objective-C

    @property (assign, readwrite, nonatomic) BOOL naturalDrawingEnabled;

    Swift

    var naturalDrawingEnabled: Bool { get set }
  • Enables the use of predictive touches. Defaults to NO. Enabling this for ink annotation improves the drawing experience.

    Declaration

    Objective-C

    @property (assign, readwrite, nonatomic) BOOL predictiveTouchesEnabled;

    Swift

    var predictiveTouchesEnabled: Bool { get set }
  • Current stroke color.

    Declaration

    Objective-C

    @property (assign, readwrite, nonatomic, nullable) UIColor *strokeColor;

    Swift

    var strokeColor: UIColor? { get set }
  • Current fill color.

    Declaration

    Objective-C

    @property (assign, readwrite, nonatomic, nullable) UIColor *fillColor;

    Swift

    var fillColor: UIColor? { get set }
  • Current line width.

    Declaration

    Objective-C

    @property (assign, readwrite, nonatomic) CGFloat lineWidth;

    Swift

    var lineWidth: CGFloat { get set }
  • Starting line end type for lines and polylines.

    Declaration

    Objective-C

    @property (assign, readwrite, nonatomic) PSPDFLineEndType lineEnd1;

    Swift

    var lineEnd1: PSPDFLineEndType { get set }
  • Ending line end type for lines and polylines.

    Declaration

    Objective-C

    @property (assign, readwrite, nonatomic) PSPDFLineEndType lineEnd2;

    Swift

    var lineEnd2: PSPDFLineEndType { get set }
  • The stroke dash pattern. Draws a solid line when nil (default).

    Declaration

    Objective-C

    @property (readwrite, copy, nonatomic, nullable) NSArray<NSNumber *> *dashArray;

    Swift

    var dashArray: [NSNumber]? { get set }
  • The border effect style.

    Declaration

    Objective-C

    @property (assign, readwrite, nonatomic)
        PSPDFAnnotationBorderEffect borderEffect;

    Swift

    var borderEffect: PSPDFAnnotationBorderEffect { get set }
  • The border effect intensity (if set to cloudy). A number describing the intensity of the effect, in the range 0 to 2. Default value: 0.

    Declaration

    Objective-C

    @property (assign, readwrite, nonatomic) CGFloat borderEffectIntensity;

    Swift

    var borderEffectIntensity: CGFloat { get set }
  • Guide color. Defaults to UIColor.pspdf_guideColor.

    Declaration

    Objective-C

    @property (assign, readwrite, nonatomic, nullable) UIColor *guideBorderColor;

    Swift

    var guideBorderColor: UIColor? { get set }
  • Converts the provided annotations into PSPDFDrawLayer objects, making them available for editing. - note: Currently only supports Ink annotations (ink eraser). - returns: An array of newly inserted layers, if any.

    Declaration

    Objective-C

    - (nonnull NSArray<PSPDFDrawLayer *> *)updateActionsForAnnotations:
        (nonnull NSArray<PSPDFInkAnnotation *> *)annotations;

    Swift

    func updateActions(for annotations: [PSPDFInkAnnotation]) -> [PSPDFDrawLayer]

    Return Value

    An array of newly inserted layers, if any.

  • Used to compute approximate line widths during drawing. When a pageView is associated this will automatically be set to it’s scaleForPageView. Defaults to 1.f.

    Declaration

    Objective-C

    @property (assign, readwrite, nonatomic) CGFloat scale;

    Swift

    var scale: CGFloat { get set }
  • Draw view zoom scale, used for zoom dependent eraser sizing. When a pageView is associated this will automatically be set to it’s scrollView.zoomScale. Defaults to 1.f.

    Declaration

    Objective-C

    @property (assign, readwrite, nonatomic) CGFloat zoomScale;

    Swift

    var zoomScale: CGFloat { get set }
  • Starts a drawing operation at the given point. The inputMode needs to be set to PSPDFDrawViewInputModeDraw.

    Declaration

    Objective-C

    - (void)startDrawingAtPoint:(PSPDFDrawingPoint)location;

    Swift

    func startDrawing(at location: PSPDFDrawingPoint)
  • Continues a drawing operation at with the given points and optional predicted points. The inputMode needs to be PSPDFDrawViewInputModeDraw.

    Declaration

    Objective-C

    - (void)continueDrawingAtPoints:(nonnull NSArray<NSValue *> *)locations
                    predictedPoints:
                        (nonnull NSArray<NSValue *> *)predictedLocations;

    Swift

    func continueDrawing(atPoints locations: [NSValue], predictedPoints predictedLocations: [NSValue])

    Parameters

    locations

    Boxed PSPDFDrawingPoint objects.

    predictedLocations

    Boxed PSPDFDrawingPoint objects.

  • Commits the drawing. The inputMode needs to be set to PSPDFDrawViewInputModeDraw.

    Declaration

    Objective-C

    - (void)endDrawing;

    Swift

    func endDrawing()
  • Cancels the drawing. The inputMode needs to be set to PSPDFDrawViewInputModeDraw.

    Declaration

    Objective-C

    - (void)cancelDrawing;

    Swift

    func cancelDrawing()
  • Defines how aggressively shapes snap to square aspect ratio. Defaults to 20.f. Set to 0.f do disable guides.

    Declaration

    Objective-C

    @property (assign, readwrite, nonatomic) CGFloat guideSnapAllowance;

    Swift

    var guideSnapAllowance: CGFloat { get set }
  • Performs an erase at the given locations. Boxed PSDFDrawingPoint objects. The inputMode needs to be set to PSPDFDrawViewInputModeErase.

    Declaration

    Objective-C

    - (void)eraseAt:(nonnull NSArray<NSValue *> *)locations;

    Swift

    func erase(at locations: [NSValue])
  • Commits the erase operation (registers the undo action, etc.). The inputMode needs to be set to PSPDFDrawViewInputModeErase.

    Declaration

    Objective-C

    - (void)endErase;

    Swift

    func endErase()