PSPDFAnnotationStateManager

Objective-C


@interface PSPDFAnnotationStateManager
    : NSObject <PSPDFOverridable, UIPencilInteractionDelegate>

Swift

class AnnotationStateManager : NSObject, Overridable, UIPencilInteractionDelegate

AnnotationStateManager holds the current annotation state and configures the associated PDFViewController to accept input related to the currently selected annotation state. The class also provides several convenience methods and user interface components required for annotation creation and configuration.

Interested parties can use KVO to observe the manager’s properties.

You should never use more than one AnnotationStateManager for any given PDFViewController. It’s recommended to use -[PSPDFViewController annotationStateManager] instead of creating your own one in order to make sure this requirement is always met.

AnnotationStateManager is internally used by AnnotationToolbar and can be re-used for any custom annotation related user interfaces.

Creating an annotation state manager requires either Annotations or Electronic Signatures to be enabled in your license. If you have Electronic Signatures without Annotations then the only state the manager may be put into is .signature

Note

Do not create this class yourself. Use the existing class that is exposed in the PSPDFViewController.
  • Unavailable

    Not the designated initializer

    Undocumented

    Declaration

    Objective-C

    PSPDF_EMPTY_INIT_UNAVAILABLE
  • Unavailable

    Not the designated initializer

    Undocumented

    Declaration

    Objective-C

    PSPDF_EMPTY_INIT_UNAVAILABLE
  • Attached pdf controller.

    Declaration

    Objective-C

    @property (nonatomic, weak, readonly) PSPDFViewController *_Nullable pdfController;

    Swift

    weak var pdfController: PDFViewController? { get }
  • Adds an annotation state delegate to the subscriber list.

    Note

    Delegates are weakly retained, but be a good citizen and manually deregister.

    Declaration

    Objective-C

    - (void)addDelegate:(nonnull id<PSPDFAnnotationStateManagerDelegate>)delegate;

    Swift

    func add(_ delegate: AnnotationStateManagerDelegate)
  • Removes an annotation state delegate from the subscriber list.

    Declaration

    Objective-C

    - (BOOL)removeDelegate:
        (nonnull id<PSPDFAnnotationStateManagerDelegate>)delegate;

    Swift

    func remove(_ delegate: AnnotationStateManagerDelegate) -> Bool
  • Active annotation state.

    Note

    Setting the state on it’s own resets the variant to nil. Prefer using setState(_, variant:), for tools that have associated variants (e.g., for .ink). Setting a state will temporarily disable the long press gesture recognizer on the PSPDFScrollView to disable the new annotation menu.

    Declaration

    Objective-C

    @property (nonatomic, copy, nullable) PSPDFAnnotationString state;

    Swift

    var state: Annotation.Tool? { get set }
  • Sets the state to the specified annotation type, if it differs from the currently set state, otherwise sets the state to nil.

    Note

    This will load the previous used color into drawColor and set all other options like lineWidth. Set these value AFTER setting the state if you want to customize them, or set the default in PSPDFStyleManager

    Declaration

    Objective-C

    - (void)toggleState:(nonnull PSPDFAnnotationString)state;

    Swift

    func toggleState(_ state: Annotation.Tool)
  • Sets the annotation variant for the current state.

    States with different variants uniquely preserve the annotation style settings. This is handy for defining multiple tools of the same annotation type, each with different style settings.

    Note

    When switching state prefer setState(_, variant:) to set the state and variant at the same time.

    Declaration

    Objective-C

    @property (nonatomic, copy, nullable) PSPDFAnnotationVariantString variant;

    Swift

    var variant: Annotation.Variant? { get set }
  • Sets the annotation type and variant at the same time.

    See

    state, variant

    Declaration

    Objective-C

    - (void)setState:(nullable PSPDFAnnotationString)state
             variant:(nullable PSPDFAnnotationVariantString)variant;

    Swift

    func setState(_ state: Annotation.Tool?, variant: Annotation.Variant?)
  • Toggles the annotation type and variant at the same time. If the state and variant both match the currently set values, it sets both to nil. Convenient for selectable toolbar buttons.

    Declaration

    Objective-C

    - (void)toggleState:(nullable PSPDFAnnotationString)state
                variant:(nullable PSPDFAnnotationVariantString)variant;

    Swift

    func toggleState(_ state: Annotation.Tool?, variant: Annotation.Variant?)
  • String identifier used as the persistence key for the current combination of state and variant.

    Declaration

    Objective-C

    @property (nonatomic, copy, readonly) PSPDFAnnotationStateVariantID _Nonnull stateVariantID;

    Swift

    var stateVariantID: Annotation.ToolVariantID { get }
  • Whether compatible annotations types may be created only with touches of type pencil. If set to stylus and a compatible annotation tool is selected, users can annotate with Apple Pencil while taping and scrolling as normal with finger touches. If set to direct then single finger touches will create annotations and two fingers must be used to scroll. The default is fromStylusManager, which effectively uses one of the other two modes depending on if PSPDFApplePencilManager enabled the Apple Pencil.

    Declaration

    Objective-C

    @property (nonatomic) PSPDFAnnotationStateManagerStylusMode stylusMode;

    Swift

    var stylusMode: AnnotationStateManagerStylusMode { get set }
  • Default/current drawing color. KVO observable. Defaults to [UIColor colorWithRed:0.121 green:0.35 blue:1. alpha:1.0]

    Note

    PSPDFKit will save the last used drawing color in NSUserDefaults. If you want to change the default value, use -[PSPDFAnnotationStyleManager setLastUsedValue:forProperty:forKey:].

    Declaration

    Objective-C

    @property (nonatomic, nullable) UIColor *drawColor;

    Swift

    var drawColor: UIColor? { get set }
  • Default/current fill color. KVO observable. Defaults to nil.

    Note

    PSPDFKit will save the last used fill color in NSUserDefaults. If you want to change the default value, use -[PSPDFAnnotationStyleManager setLastUsedValue:forProperty:forKey:].

    Declaration

    Objective-C

    @property (nonatomic, nullable) UIColor *fillColor;

    Swift

    var fillColor: UIColor? { get set }
  • Current drawing line width. Defaults to 3.. KVO observable.

    Note

    PSPDFKit will save the last used line width in NSUserDefaults. If you want to change the default value, use -[PSPDFAnnotationStyleManager setLastUsedValue:forProperty:forKey:].

    Declaration

    Objective-C

    @property (nonatomic) CGFloat lineWidth;

    Swift

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

    Note

    PSPDFKit will save the last used line end in NSUserDefaults. If you want to change the default value, use -[PSPDFAnnotationStyleManager setLastUsedValue:forProperty:forKey:].

    Declaration

    Objective-C

    @property (nonatomic) PSPDFLineEndType lineEnd1;

    Swift

    var lineEnd1: AbstractLineAnnotation.EndType { get set }
  • Ending line end type for lines and polylines. KVO observable.

    Note

    PSPDFKit will save the last used line end in NSUserDefaults. If you want to change the default value, use -[PSPDFAnnotationStyleManager setLastUsedValue:forProperty:forKey:].

    Declaration

    Objective-C

    @property (nonatomic) PSPDFLineEndType lineEnd2;

    Swift

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

    Declaration

    Objective-C

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

    Swift

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

    Declaration

    Objective-C

    @property (nonatomic) PSPDFAnnotationBorderEffect borderEffect;

    Swift

    var borderEffect: Annotation.BorderEffect { get set }
  • The border effect intensity (if set to cloudy)

    Declaration

    Objective-C

    @property (nonatomic) CGFloat borderEffectIntensity;

    Swift

    var borderEffectIntensity: CGFloat { get set }
  • Defines a custom blend mode. Supported values include kCGBlendModeNormal to kCGBlendModeExclusion.

    Declaration

    Objective-C

    @property (nonatomic) CGBlendMode blendMode;

    Swift

    var blendMode: CGBlendMode { get set }
  • Font name for free text annotations. KVO observable.

    Note

    PSPDFKit will save the last used font name in NSUserDefaults. If you want to change the default value, use -[PSPDFAnnotationStyleManager setLastUsedValue:forProperty:forKey:].

    Declaration

    Objective-C

    @property (nonatomic, copy, nullable) NSString *fontName;

    Swift

    var fontName: String? { get set }
  • Font size for free text annotations. KVO observable.

    Note

    PSPDFKit will save the last used font size in NSUserDefaults. If you want to change the default value, use -[PSPDFAnnotationStyleManager setLastUsedValue:forProperty:forKey:].

    Declaration

    Objective-C

    @property (nonatomic) CGFloat fontSize;

    Swift

    var fontSize: CGFloat { get set }
  • Text alignment for free text annotations. KVO observable.

    Note

    PSPDFKit will save the last used text alignment in NSUserDefaults. If you want to change the default value, use -[PSPDFAnnotationStyleManager setLastUsedValue:forProperty:forKey:].

    Declaration

    Objective-C

    @property (nonatomic) NSTextAlignment textAlignment;

    Swift

    var textAlignment: NSTextAlignment { get set }
  • Outline color for redaction annotations. KVO observable.

    Note

    PSPDFKit will save the last used outline color in NSUserDefaults. If you want to change the default value, use -[PSPDFAnnotationStyleManager setLastUsedValue:forProperty:forKey:].

    Declaration

    Objective-C

    @property (nonatomic, nullable) UIColor *outlineColor;

    Swift

    var outlineColor: UIColor? { get set }
  • Overlay text for redaction annotations. KVO observable.

    Note

    PSPDFKit will save the last used overlay text value in NSUserDefaults. If you want to change the default value, use -[PSPDFAnnotationStyleManager setLastUsedValue:forProperty:forKey:].

    Declaration

    Objective-C

    @property (nonatomic, copy, nullable) NSString *overlayText;

    Swift

    var overlayText: String? { get set }
  • Repeat overlay text for redaction annotations. KVO observable.

    Note

    PSPDFKit will save the last used repeat overlay text value in NSUserDefaults. If you want to change the default value, use -[PSPDFAnnotationStyleManager setLastUsedValue:forProperty:forKey:].

    Declaration

    Objective-C

    @property (nonatomic) BOOL repeatOverlayText;

    Swift

    var repeatOverlayText: Bool { get set }
  • Undocumented

    Declaration

    Objective-C

    @property (nonatomic, readonly) UIPencilInteraction *pencilInteraction

    Swift

    var pencilInteraction: UIPencilInteraction { get }
  • Shows the style picker for the current annotation class and configures it with annotation state manager style attributes.

    Note

    This will change style properties on this annotation state manager.

    Declaration

    Objective-C

    - (nullable PSPDFAnnotationStyleViewController *)
          toggleStylePicker:(nullable id)sender
        presentationOptions:
            (nullable NSDictionary<PSPDFPresentationOption, id> *)options;

    Swift

    func toggleStylePicker(_ sender: Any?, presentationOptions options: [PresentationOption : Any]? = nil) -> PSPDFAnnotationStyleViewController?

    Parameters

    sender

    A UIView or UIBarButtonItem used as the anchor view for the popover controller.

    options

    A dictionary of presentation options. See PSPDFPresentationActions.h for possible values.

  • Displays a PSPDFSignatureViewController and toggles the state to Annotation.Tool.signature.

    This requires Electronic Signatures to be enabled in your license. (This method is also available for licenses with Annotations obtained in April 2021 or earlier. In that case, it will show a more limited signing UI that only supports drawing.)

    Declaration

    Objective-C

    - (nullable UIViewController *)
        toggleSignatureController:(nullable id)sender
              presentationOptions:
                  (nullable NSDictionary<PSPDFPresentationOption, id> *)options;

    Swift

    func toggleSignatureController(_ sender: Any?, presentationOptions options: [PresentationOption : Any]? = nil) -> UIViewController?

    Parameters

    sender

    A UIView or UIBarButtonItem used as the anchor view for the popover controller.

    options

    A dictionary of presentation options. See PSPDFPresentationActions.h for possible values.

  • Displays a PSPDFStampViewController and toggles the state to PSPDFAnnotationStringStamp.

    Declaration

    Objective-C

    - (nullable UIViewController *)
        toggleStampController:(nullable id)sender
          presentationOptions:
              (nullable NSDictionary<PSPDFPresentationOption, id> *)options;

    Swift

    func toggleStampController(_ sender: Any?, presentationOptions options: [PresentationOption : Any]? = nil) -> UIViewController?

    Parameters

    sender

    A UIView or UIBarButtonItem used as the anchor view for the popover controller.

    options

    A dictionary of presentation options. See PSPDFPresentationActions.h for possible values.

  • Declaration

    Objective-C

    - (nullable UIViewController *)
        toggleSavedAnnotations:(nullable id)sender
           presentationOptions:
               (nullable NSDictionary<PSPDFPresentationOption, id> *)options;

    Swift

    func toggleSavedAnnotations(_ sender: Any?, presentationOptions options: [PresentationOption : Any]? = nil) -> UIViewController?

    Parameters

    sender

    A UIView or UIBarButtonItem used as the anchor view for the popover controller.

    options

    A dictionary of presentation options. See PSPDFPresentationActions.h for possible values.

  • Displays a PSPDFImagePickerController and toggles the state to PSPDFAnnotationStringImage. This will display an alert if the user selects UIImagePickerControllerSourceTypeCamera but does not grant permission.

    Declaration

    Objective-C

    - (nullable UIViewController *)
        toggleImagePickerController:(nullable id)sender
                presentationOptions:
                    (nullable NSDictionary<PSPDFPresentationOption, id> *)options;

    Swift

    func toggleImagePickerController(_ sender: Any?, presentationOptions options: [PresentationOption : Any]? = nil) -> UIViewController?

    Parameters

    sender

    A UIView or UIBarButtonItem used as the anchor view for the popover controller.

    options

    A dictionary of presentation options. See PSPDFPresentationActions.h for possible values.

  • Checks if state is a drawing state.

    Declaration

    Objective-C

    - (BOOL)isDrawingState:(nullable PSPDFAnnotationString)state;

    Swift

    func isDrawingState(_ state: Annotation.Tool?) -> Bool
  • Checks if state is a markup annotation state. (Highlight, underline, strikeout, and squiggly.).

    Declaration

    Objective-C

    - (BOOL)isMarkupAnnotationState:(nullable PSPDFAnnotationString)state;

    Swift

    func isMarkupAnnotationState(_ state: Annotation.Tool?) -> Bool
  • Subclass to control if the state supports a style picker.

    Declaration

    Objective-C

    - (BOOL)stateShowsStylePicker:(nullable PSPDFAnnotationString)state;

    Swift

    func stateShowsStylePicker(_ state: Annotation.Tool?) -> Bool