1

我创建了一个 PDFView。现在我只想添加一个 Ink 注释。所以我覆盖touchesBegan,touchesMovedtouchesEnded方法并得到UIBezierPath. 在touchesEnded我创建了一个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)
    }
}
4

0 回答 0