Текстовый курсор вне поля зрения при наборе текста - PullRequest
0 голосов
/ 04 марта 2019

У меня есть несколько аннотаций PDFKit, добавленных в мой PDF-документ.Когда пользователь выбирает текстовые аннотации для добавления текста, появляется клавиатура, и документ прокручивается вверх, а курсор на экране больше не отображается.Я пытался рассматривать PDF-документ как текстовое поле, но это не работает.Как удерживать курсор на экране или по центру над клавиатурой, когда пользователь добавляет текст в аннотацию PDF?

Вот мой код:

import UIKit
import PDFKit

class PDFfun: UIViewController {

    var pdfView = PDFView()
    var textFieldMultiline3 = PDFAnnotation()
    let document = PDFDocument(url: Bundle.main.url(forResource: "DOCUMENT", withExtension: "pdf")!)


override func viewDidLoad() {
    super.viewDidLoad()

    pdfView = PDFView(frame: self.view.frame)



        pdfView.document = document
        pdfView.autoScales = true
        pdfView.backgroundColor = UIColor.lightGray
        self.insertMultilineTextBoxIntoOneOneNine(document!.page(at: 119)!)
        pdfView.translatesAutoresizingMaskIntoConstraints = false
    view.addSubview(pdfView)
    view.addConstraints([
        NSLayoutConstraint(item: pdfView, attribute: .leading, relatedBy: .equal, toItem: view, attribute: .leading, multiplier: 1, constant: 0),
        NSLayoutConstraint(item: pdfView, attribute: .trailing, relatedBy: .equal, toItem: view, attribute: .trailing, multiplier: 1, constant: 0),
        NSLayoutConstraint(item: pdfView, attribute: .top, relatedBy: .equal, toItem: view, attribute: .top, multiplier: 1, constant: 0),
        NSLayoutConstraint(item: pdfView, attribute: .bottom, relatedBy: .equal, toItem: view, attribute: .bottom, multiplier: 1, constant: 0)
        ])
}
func insertMultilineTextBoxIntoOneOneNine(_ page: PDFPage) {

    _ = page.bounds(for: .cropBox)

    let textFieldMultilineBounds3 = CGRect(x: 27, y: 50, width: 339, height: 510)
    textFieldMultiline3 = PDFAnnotation(bounds: textFieldMultilineBounds3, forType: PDFAnnotationSubtype(rawValue: PDFAnnotationSubtype.widget.rawValue), withProperties: nil)
    textFieldMultiline3.widgetFieldType = PDFAnnotationWidgetSubtype(rawValue: PDFAnnotationWidgetSubtype.text.rawValue)
    textFieldMultiline3.backgroundColor = UIColor.white.withAlphaComponent(1)
    textFieldMultiline3.font = UIFont(name: "Arial", size: 15)
    textFieldMultiline3.isMultiline = true
    page.addAnnotation(textFieldMultiline3)
}
 override func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator) {
    super.viewWillTransition(to: size, with: coordinator)
    if UIDevice.current.orientation.isLandscape {
        print("landscape")
        pdfView = PDFView(frame: view.frame)
        pdfView.autoScales = true
    } else {
        print("portait")
        pdfView = PDFView(frame: view.frame)
        pdfView.autoScales = true
    }
}
override func viewDidLayoutSubviews() {
    super.viewDidLayoutSubviews()

    pdfView.frame = view.frame
}
override var prefersStatusBarHidden: Bool {
    return false
}
override var preferredStatusBarStyle: UIStatusBarStyle {
    return .lightContent
}

}

...