0

at the moment I try to implement a PDF view with annotations in my iOS App. I implemented a function for adding note annotations as a text annotation like this:

    let rect = CGRect.init(x: lastLongPressLoc.x, y: lastLongPressLoc.y, width: 24, height: 24)
    let ann = PDFAnnotation(bounds: rect, forType: PDFAnnotationSubtype.text, withProperties: nil)
    ann.font = UIFont(name: "Helvetica", size: 20.0)
    ann.interiorColor = UIColor.yellow
    ann.popup?.interiorColor = UIColor.yellow
    ann.color = UIColor.yellow
    ann.iconType = PDFTextAnnotationIconType.comment
    self.currentPage?.addAnnotation(ann)

Adding and editing the annotation works quite fine. For deleting and other options I now want to implement some buttons above the keyboard which should appear when the annotation was tapped. For widget annotations I found a great thread, that helped me with this (Configuring keyboard settings within PDFView form fields). The solution recommends to search the active subviews for a UITextView when the annotation gets tapped via the PDFViewAnnotationHit notification and manipulate the inputAccessoryView property. I assume that the editing of popup annotation works a bit different. While editing a text annotation I unfortunately cannot find an UITextView in my app.

Has someone came across this problem or has better insights in the PDFKit framework and can give me a hint?

Thanks for your time!

WLash
  • 27
  • 4

1 Answers1

0

Finally found a solution. The UITextView for this kind of annotations is not added to the subviews of the PDFView. It is shown in a popover in a transition view as child of the window. So, when you search the subviews of self.window! recursively you can find the UITextView and manipulate it (like mentioned in this thread: Swift: Recursively cycle through all subviews to find a specific class and append to an array). Unfortunately the popover is not available on pdf views annotation hit. At the moment I observe the UIResponder.keyboardWillShowNotification. Not very nice but this will do it for now. If somebody comes across this thread, I would appreciate you opinion on manipulating the text views of the annotations in a better way. :)

WLash
  • 27
  • 4