---
title: "Annotation state manager on iOS | Nutrient SDK"
canonical_url: "https://www.nutrient.io/guides/ios/annotations/annotation-state-manager/"
md_url: "https://www.nutrient.io/guides/ios/annotations/annotation-state-manager.md"
last_updated: "2026-06-09T10:38:40.889Z"
description: "AnnotationStateManager is responsible for all state related to annotation creation in a PDFViewController. for Nutrient iOS SDK."
---

# Annotation state manager on iOS

[`AnnotationStateManager`](https://www.nutrient.io/api/ios/documentation/pspdfkitui/annotationstatemanager) is responsible for all state related to annotation creation in a [`PDFViewController`](https://www.nutrient.io/api/ios/documentation/pspdfkitui/pdfviewcontroller).

Don’t create an instance of [`AnnotationStateManager`](https://www.nutrient.io/api/ios/documentation/pspdfkitui/annotationstatemanager) yourself. Instead, use the [`annotationStateManager`](https://www.nutrient.io/api/ios/documentation/pspdfkitui/pdfviewcontroller/annotationstatemanager) exposed in [`PDFViewController`](https://www.nutrient.io/api/ios/documentation/pspdfkitui/pdfviewcontroller).

Using [`AnnotationStateManager`](https://www.nutrient.io/api/ios/documentation/pspdfkitui/annotationstatemanager), you can programmatically set or toggle all the different states used for annotation creation. Additionally, when tapping on annotation tools, [`AnnotationToolbar`](https://www.nutrient.io/api/ios/documentation/pspdfkitui/annotationtoolbar) toggles annotation states while using [`AnnotationStateManager`](https://www.nutrient.io/api/ios/documentation/pspdfkitui/annotationstatemanager) internally. Therefore, programmatically toggling a state is automatically represented on the annotation toolbar, if it’s visible.

## Custom annotation user interface

If you don’t want to use [`AnnotationToolbar`](https://www.nutrient.io/api/ios/documentation/pspdfkitui/annotationtoolbar), but instead provide your own user interface related to annotations, [`AnnotationStateManager`](https://www.nutrient.io/api/ios/documentation/pspdfkitui/annotationstatemanager) is the class you want to use to connect your user interface to Nutrient.

## Customize behavior

You can also customize the behavior when showing the annotation toolbar to make it automatically select an annotation tool and immediately start drawing. This can be done by setting a state using [`AnnotationStateManager`](https://www.nutrient.io/api/ios/documentation/pspdfkitui/annotationstatemanager) when the toolbar is made visible. This can be enabled using the following code snippet:

### SWIFT

```swift

self.annotationToolbarController?.annotationToolbar.toolbarDelegate = self

// `FlexibleToolbarDelegate`
func flexibleToolbarWillShow(_ toolbar: FlexibleToolbar) {
    self.annotationStateManager.setState(.ink, variant:.inkPen)
}

```

### OBJECTIVE-C

```objc

self.annotationToolbarController.annotationToolbar.toolbarDelegate = self;

// `PSPDFFlexibleToolbarDelegate`

- (void)flexibleToolbarWillShow:(PSPDFFlexibleToolbar *)toolbar {
    [self.annotationStateManager setState:PSPDFAnnotationStringInk variant:PSPDFAnnotationVariantStringInkPen];
}

```

Do not call [`hideToolbar(animated:completion:)`](https://www.nutrient.io/api/ios/documentation/pspdfkitui/flexibletoolbarcontroller/hidetoolbar(animated:completion:)) in your `PDFViewController`’s `viewWillDisappear(_:):`. It will exit edit mode, and it may lead to unexpected behaviors — for example, when you’re invoking the stamp picker on an iPhone, which is presented modally, `viewWillDisappear(_:)` will be called, thereby causing the stamp picker to be dismissed immediately. The annotation state is reset as soon as the annotation toolbar is hidden.

### SWIFT

```swift

class CustomPDFViewController: PDFViewController {

    override func viewWillDisappear(_ animated: Bool) {
        super.viewWillDisappear(animated)

        // Do not hide the annotation toolbar.
        // self.annotationToolbarController?.hideToolbar(animated: animated)
    }

}

```

### OBJECTIVE-C

```objc

@implementation CustomPDFViewController

- (void)viewWillDisappear:(BOOL)animated {
    [super viewWillDisappear:animated];

    // Do not hide the annotation toolbar.
    // [self.annotationToolbarController hideToolbarAnimated:animated completion:nil];
}

@end

```
---

## Related pages

- [Annotations object model on iOS](/guides/ios/annotations/the-annotation-object-model.md)
- [Define annotation behavior with flags on iOS](/guides/ios/annotations/annotation-flags.md)
- [How to embed files in PDF annotations on iOS](/guides/ios/annotations/create-edit-and-remove/attach-a-file.md)
- [Setting annotation authors on iOS](/guides/ios/annotations/annotation-author-name.md)
- [Detect changes to PDF annotations in iOS apps](/guides/ios/annotations/detecting-if-annotations-have-changed.md)
- [Defining annotation blend modes on iOS](/guides/ios/annotations/annotation-blend-modes.md)
- [Drag-and-drop annotations on iOS](/guides/ios/annotations/create-edit-and-remove/drag-and-drop.md)
- [Disable PDF annotation editing for iOS users](/guides/ios/annotations/create-edit-and-remove/disable-editing.md)
- [Image picker: Add image annotations to PDFs on iOS](/guides/ios/miscellaneous/image-picker.md)
- [Programmatically create PDF annotations on iOS](/guides/ios/annotations/programmatically-creating-annotations.md)
- [Undo and redo annotations on iOS](/guides/ios/features/undo-redo.md)
- [Z-index for annotation stacking order on iOS](/guides/ios/annotations/annotation-z-index.md)

