Добавить несколько PDF аннотации PDFView и изменить изображение аннотации на PDFAction - PullRequest
0 голосов
/ 10 июля 2019

Мне нужно показать кнопку на каждой странице PDF в pdfview, я могу добиться этого, используя PDFAnnotation Widget и PDFAction, но я не могу получить событие PDFAnnotation on buttonTouch, чтобы обновить его изображение .

    var bookMarkButton = ImageStampAnnotation(with: #imageLiteral(resourceName: "Bookmark-N"), forBounds: CGRect(x: pdfView.frame.width-50, y: pdfView.frame.height-50, width: 30, height: 30), withProperties: nil)
    bookMarkButton.widgetControlType = .pushButtonControl
    bookMarkButton.action = PDFActionURL(url: URL(string: "didtap")!)

    guard let pdf = pdfView.document else {
        return
    }
    for i in 0 ..< pdf.pageCount {
        pdf.page(at: i)?.addAnnotation(bookMarkButton)

    }

  func pdfViewWillClick(onLink sender: PDFView, with url: URL) {
    if let documentURL = pdfDocument?.documentURL?.absoluteString {
        var bookmarks = UserDefaults.standard.array(forKey: documentURL) as? [Int] ?? [Int]()
        if let currentPage = pdfView.currentPage,
            let pageIndex = pdfDocument?.index(for: currentPage) {
            if let index = bookmarks.index(of: pageIndex) {
                bookmarks.remove(at: index)
                UserDefaults.standard.set(bookmarks, forKey: documentURL)
                bookmarkButton.image = #imageLiteral(resourceName: "Bookmark-N")
            } else {
                UserDefaults.standard.set((bookmarks + [pageIndex]).sorted(), forKey: documentURL)
                bookmarkButton.image = #imageLiteral(resourceName: "Bookmark-P")
            }
        }
    }
  }
...