Ios 用不同坐标系注释PDF
我正在用PDFKIT在pdf上画一条线。我覆盖触摸开始、移动等,如下所示,将我的触摸记录在pdfView的documentView中:Ios 用不同坐标系注释PDF,ios,swift,annotations,touch,pdfkit,Ios,Swift,Annotations,Touch,Pdfkit,我正在用PDFKIT在pdf上画一条线。我覆盖触摸开始、移动等,如下所示,将我的触摸记录在pdfView的documentView中: override func touchesMoved(_ touches: Set<UITouch>, with event: UIEvent?) { // 6 swiped = true if let touch = touches.first { le
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
}
}
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)
}
如何对齐坐标系,使我在屏幕上触摸的位置就是绘制注释的位置?对于感兴趣的人,我使用框架随附的以下函数解决了这个问题,该框架将点从视图空间转换为页面空间
func convert(_ point: CGPoint, to page: PDFPage) -> CGPoint
希望这能对你们中的一些人有所帮助。对于那些感兴趣的人,我使用框架中的以下函数解决了这个问题,该框架将一个点从视图空间转换为页面空间
func convert(_ point: CGPoint, to page: PDFPage) -> CGPoint
希望这能对你们中的一些人有所帮助