PSPDFAnnotationStateManager


@interface PSPDFAnnotationStateManager : NSObject <PSPDFOverridable>

PSPDFAnnotationStateManager holds the current annotation state and configures the associated PSPDFViewController 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 PSPDFAnnotationStateManager for any given PSPDFViewController. It’s recommended to use -[PSPDFViewController annotationStateManager] instead of creating your own one in order to make sure this requirement is always met.

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

Note

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

    Undocumented

    Declaration

    Objective-C

    PSPDF_EMPTY_INIT_UNAVAILABLE
  • Unavailable

    Undocumented

    Declaration

    Objective-C

    PSPDF_EMPTY_INIT_UNAVAILABLE
  • Attached pdf controller.

    Declaration

    Objective-C

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

    Swift

    weak var pdfController: PSPDFViewController? { 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: PSPDFAnnotationStateManagerDelegate)
  • Removes an annotation state delegate from the subscriber list.

    Declaration

    Objective-C

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

    Swift

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

    Note

    Setting a state will temporarily disable the long press gesture recognizer on the PSPDFScrollView to disable the new annotation menu. Setting the state on it’s own resets the variant to nil.

    Declaration

    Objective-C

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

    Swift

    var state: AnnotationString? { 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: AnnotationString)
  • 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.

    Declaration

    Objective-C

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

    Swift

    var variant: AnnotationVariantString? { 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: AnnotationString?, variant: AnnotationVariantString?)
  • 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: AnnotationString?, variant: AnnotationVariantString?)
  • String identifier used as the persistence key for the current combination of state and variant.

    Declaration

    Objective-C

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

    Swift

    var stateVariantID: AnnotationStateVariantID { get }
  • Input mode (draw or erase) for PSPDFDrawView instances. Defaults to PSPDFDrawViewInputModeDraw.

    Declaration

    Objective-C

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

    Swift

    var drawingInputMode: PSPDFDrawViewInputMode { get set }
  • Whether compatible annotations types may be created only with touches of type UITouchTypeStylus. 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 effectivly uses one of the other two modes depending on if the global PSPDFStylusManager is using the Apple Pencil.

    Declaration

    Objective-C

    @property (assign, readwrite, nonatomic)
        PSPDFAnnotationStateManagerStylusMode stylusMode;

    Swift

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

    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 (assign, readwrite, 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 (assign, readwrite, nonatomic, nullable) UIColor *fillColor;

    Swift

    var fillColor: UIColor? { get set }
  • Current drawing line width. Defaults to 3.f. 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 (assign, readwrite, 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 (assign, readwrite, nonatomic) PSPDFLineEndType lineEnd1;

    Swift

    var lineEnd1: PSPDFLineEndType { 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 (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)

    Declaration

    Objective-C

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

    Swift

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

    Declaration

    Objective-C

    @property (assign, readwrite, 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 (readwrite, copy, nonatomic, 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 (assign, readwrite, 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 (assign, readwrite, 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 (assign, readwrite, nonatomic, nullable) UIColor *outlineColor;

    Swift

    var outlineColor: UIColor? { get set }
  • 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<NSString *, id> *)options;

    Swift

    func toggleStylePicker(_ sender: Any?, presentationOptions options: [String : 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 PSPDFAnnotationStringSignature.

    Declaration

    Objective-C

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

    Swift

    func toggleSignatureController(_ sender: Any?, presentationOptions options: [String : 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<NSString *, id> *)options;

    Swift

    func toggleStampController(_ sender: Any?, presentationOptions options: [String : 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<NSString *, id> *)options;

    Swift

    func toggleSavedAnnotations(_ sender: Any?, presentationOptions options: [String : 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<NSString *, id> *)options;

    Swift

    func toggleImagePickerController(_ sender: Any?, presentationOptions options: [String : 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: AnnotationString?) -> 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: AnnotationString?) -> Bool
  • Subclass to control if the state supports a style picker.

    Declaration

    Objective-C

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

    Swift

    func stateShowsStylePicker(_ state: AnnotationString?) -> Bool
  • Only allowed in drawing state (ink, line, polyline, polygon, circle, ellipse)

    Declaration

    Objective-C

    - (void)cancelDrawingAnimated:(BOOL)animated;

    Swift

    func cancelDrawing(animated: Bool)
  • Undocumented

    Declaration

    Objective-C

    - (void)doneDrawingAnimated:(BOOL)animated;

    Swift

    func doneDrawing(animated: Bool)
  • Color management.

    Declaration

    Objective-C

    - (void)setLastUsedColor:(nullable UIColor *)lastUsedDrawColor
            annotationString:(nonnull PSPDFAnnotationString)annotationString;

    Swift

    func setLastUsedColor(_ lastUsedDrawColor: UIColor?, annotationString: AnnotationString)
  • Undocumented

    Declaration

    Objective-C

    - (nullable UIColor *)lastUsedColorForAnnotationString:(PSPDFAnnotationString)annotationString;

    Swift

    func lastUsedColor(forAnnotationString annotationString: AnnotationString) -> UIColor?
  • If we’re in drawing state, this dictionary contains the PSPDFDrawView classes that are overlaid on the PSPDFPageView. The key is the current page.

    Declaration

    Objective-C

    @property (readonly, nonatomic)
        NSDictionary<NSNumber *, PSPDFDrawView *> *_Nonnull drawViews;

    Swift

    var drawViews: [NSNumber : PSPDFDrawView] { get }