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 thePSPDFViewController.
-
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 usingsetState(_, variant:)
, for tools that have associated variants (e.g., for.ink
). Setting a state will temporarily disable the long press gesture recognizer on thePSPDFScrollView
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 thestate
tonil
.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 prefersetState(_, 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, variantDeclaration
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 tostylus
and a compatible annotation tool is selected, users can annotate with Apple Pencil while taping and scrolling as normal with finger touches. If set todirect
then single finger touches will create annotations and two fingers must be used to scroll. The default isfromStylusManager
, which effectively uses one of the other two modes depending on ifPSPDFApplePencilManager
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 inNSUserDefaults
. 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 inNSUserDefaults
. 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 inNSUserDefaults
. 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 inNSUserDefaults
. 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 inNSUserDefaults
. 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
tokCGBlendModeExclusion
.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 inNSUserDefaults
. 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 inNSUserDefaults
. 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 inNSUserDefaults
. 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 inNSUserDefaults
. 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 inNSUserDefaults
. 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 inNSUserDefaults
. 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 }
-
The interaction used to handle actions from Apple Pencil.
The delegate is the annotation state manager. The interaction is disabled initially.
AnnotationToolbar
will enabled and disable the interaction when the toolbar appears and disappears respectively.Declaration
Objective-C
@property (nonatomic, readonly) UIPencilInteraction *_Nonnull 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
orUIBarButtonItem
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 toAnnotation.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
orUIBarButtonItem
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 toPSPDFAnnotationStringStamp
.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
orUIBarButtonItem
used as the anchor view for the popover controller.options
A dictionary of presentation options. See PSPDFPresentationActions.h for possible values.
-
Displays a
PSPDFSavedAnnotationsViewController
and toggles the state toPSPDFAnnotationStringSavedAnnotations
.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
orUIBarButtonItem
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 toPSPDFAnnotationStringImage
. 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
orUIBarButtonItem
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
-
Color management.
Declaration
Objective-C
- (void)setLastUsedColor:(nullable UIColor *)lastUsedDrawColor annotationString:(nonnull PSPDFAnnotationString)annotationString;
Swift
func setLastUsedColor(_ lastUsedDrawColor: UIColor?, annotationString: Annotation.Tool)
-
Undocumented
Declaration
Objective-C
- (nullable UIColor *)lastUsedColorForAnnotationString:(PSPDFAnnotationString)annotationString;
Swift
func lastUsedColor(forAnnotationString annotationString: Annotation.Tool) -> UIColor?
-
If we’re in drawing state, this dictionary contains the
PSPDFDrawView
classes that are overlaid on thePDFPageView
. The key is the current page.Declaration
Objective-C
@property (nonatomic, readonly) NSDictionary<NSNumber *, PSPDFDrawView *> *_Nonnull drawViews;
Swift
var drawViews: [NSNumber : DrawView] { get }