0
PDFKITを使用してPDF上に線を描いています。次のように私はタッチが始まった上書き、pdfViewのdocumentViewに私のタッチをログに記録するなど、以下のようにして移動:異なる座標系でPDFに注釈を付ける
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
}
}
をしかし、あなたは以下の私のイメージから見ることができるように私は、画面と赤に触れる場所(黒い線がありますラインは注釈が描かれている場所です)。タッチ座標系は画面の左上の(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)
}
注釈が描かれている場合、私は画面上に触れる場所があるので、私は座標系を揃えることができますどのように?