【发布时间】:2018-04-25 08:23:45
【问题描述】:
我正在使用 PDFKIT 在 pdf 上画一条线。我覆盖了开始、移动等的触摸,如下所示记录我在 pdfView 的 documentView 上的触摸:
override func touchesMoved(_ touches: Set<UITouch>,
with event: UIEvent?) {
// 6
swiped = true
if let touch = touches.first {
let currentPoint = touch.location(in: pdfView.documentView)
drawLineFrom(fromPoint: lastPoint, toPoint: currentPoint)
addAnnotation(fromPoint: lastPoint, toPoint: currentPoint)
// 7
lastPoint = currentPoint
}
}
但是,如下图所示(黑线是我触摸屏幕的位置,红线是绘制注释的位置)。 touches坐标系在屏幕左上角(0,0),pdf从屏幕左下角(0,0)开始标注。
我的添加注释功能如下:
func addAnnotation(fromPoint: CGPoint, toPoint: CGPoint) {
let page = pdfView.document?.page(at: 0)
let bounds = CGRect(x: 0, y: 0, width: 600, height: 600)
let line = PDFAnnotation(bounds: bounds, forType: .line, withProperties: nil)
line.startPoint = fromPoint
line.endPoint = toPoint
line.startLineStyle = .none
line.endLineStyle = .none
line.color = .red
let border = PDFBorder()
border.lineWidth = 4.0
line.border = border
page?.addAnnotation(line)
}
如何对齐坐标系,以便我在屏幕上触摸的位置是绘制注释的位置?
【问题讨论】:
标签: ios swift annotations touch pdfkit