Как реализовать аннотацию чернил PDFKit с помощью UIBezierPath - PullRequest
0 голосов
/ 19 мая 2018

Я создал PDFView.Теперь я просто хочу добавить аннотацию к чернилам.Поэтому я переопределяю методы touchesBegan, touchesMoved и touchesEnded и получаю UIBezierPathtouchesEnded я создал PDFAnnotation и добавил это UIBezierPath.Затем я добавил эту аннотацию на мою PDFView текущую страницу.Но я не мог получить правильную аннотацию.Границы аннотации отличаются от того, что я написал.

override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?)
{
    path = UIBezierPath()
    path?.lineWidth = 4.0

    let touch: UITouch = touches.first!
    path?.move(to: touch.location(in: self.pdfView))
}

override func touchesMoved(_ touches: Set<UITouch>, with event: UIEvent?)
{
    let touch: UITouch = touches.first!
    path?.addLine(to: touch.location(in: self.pdfView))
    self.pdfView.setNeedsDisplay()
    path?.stroke()
}

override func touchesEnded(_ touches: Set<UITouch>, with event: UIEvent?) {

    let touch = touches.first
    path?.addLine(to: touch!.location(in: self.pdfView))
    self.pdfView.setNeedsDisplay()
    let annotation = PDFAnnotation(bounds: self.pdfView.bounds, forType: .ink, withProperties: nil)
    annotation.add(self.path!)
    if let currentPage = self.pdfView.currentPage
    {
        currentPage.addAnnotation(annotation)
    }
}
...