How do I disable rotation for annotations?

Q: How do I disable rotation for annotations?

A: You can disable the rotation for annotations by subclassing the ResizableView and overriding the allowRotating property based on your requirements. In the below example, we are disabling rotation for FreeTextAnnotations.

Copy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
class DisabledFreeTextAnnotationResizableView: ResizableView {

    /// Backing variable to store the values set to `allowRotating`.
    var allowRotatingBackingStore = true

    override var allowRotating: Bool {
        /// Store the value set by other resources
        set { allowRotatingBackingStore = newValue }

        get {
            // Return false if the annotation tracked is of FreeTextAnnotation type
            // Otherwise return the value in the backing variable.
            if self.trackedAnnotations.first is FreeTextAnnotation {
                return false
            } else {
                return allowRotatingBackingStore
            }
        }
    }
}
...
...
// Creating the `PDFController` to edit the PDF.
let pdfController = PDFViewController(document: document) {
    // Register our custom subclass of `ResizableView`.
    $0.overrideClass(ResizableView.self, with: DisabledFreeTextAnnotationResizableView.self)
}