簡體   English   中英

在 PDFKit 中為文本注釋配置鍵盤 (iOS14)

[英]Configuring keyboard in PDFKit for text annotations (iOS14)

目前,我嘗試在我的 iOS 應用程序中實現帶有注釋的 PDF 視圖。 我實現了一個 function 用於添加注釋注釋作為文本注釋,如下所示:

    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)

添加和編輯注釋工作得很好。 對於刪除和其他選項,我現在想在鍵盤上方實現一些按鈕,這些按鈕應該在點擊注釋時出現。 對於小部件注釋,我找到了一個很棒的線程,這對我有幫助( 在 PDFView 表單字段中配置鍵盤設置)。 該解決方案建議在通過 PDFViewAnnotationHit 通知點擊注釋時搜索 UITextView 的活動子視圖並操作 inputAccessoryView 屬性。 我假設彈出注釋的編輯工作有點不同。 不幸的是,在編輯文本注釋時,我在我的應用程序中找不到 UITextView。

有人遇到過這個問題或者對 PDFKit 框架有更好的見解,可以給我一個提示嗎?

謝謝你的時間!

終於找到了解決辦法。 此類注釋的 UITextView 不會添加到 PDFView 的子視圖中。 它在轉換視圖的彈出窗口中顯示為 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 ). 不幸的是,彈出框在 pdf 視圖注釋命中時不可用。 目前我觀察到 UIResponder.keyboardWillShowNotification。 不是很好,但現在就可以了。 如果有人遇到此線程,我將不勝感激您對以更好的方式操作注釋的文本視圖的意見。 :)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM