我创建了一个PDFView。现在我只想添加一个Ink注释。因此,我会覆盖touchesBegan
,touchesMoved
和touchesEnded
方法并获取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)
}
}