gpt4 book ai didi

swift - iOS 11 PDFKit 不更新注释位置

转载 作者:可可西里 更新时间:2023-11-01 01:12:02 25 4
gpt4 key购买 nike

我正在构建一个在 iPad 上编辑 PDF 的应用。

我正在尝试使用添加到 PDFView 的 super View 的 panGesture 识别器来实现注释的拖动。问题是注释的新矩形边界已分配,但更改未反射(reflect)在屏幕上。

这是我的代码:

@objc func handlePanGesture(panGesture: UIPanGestureRecognizer) {
let touchLocation = panGesture.location(in: pdfView)

guard let page = pdfView.page(for: touchLocation, nearest: true) else {
return
}
let locationOnPage = pdfView.convert(touchLocation, to: page)

switch panGesture.state {
case .began:

guard let annotation = page.annotation(at: locationOnPage) else {
return
}
currentlySelectedAnnotation = annotation
case .changed:

guard let annotation = currentlySelectedAnnotation else {
return
}
let initialBounds = annotation.bounds
annotation.bounds = CGRect(origin: locationOnPage,
size: initialBounds.size)

print("move to \(locationOnPage)")
case .ended, .cancelled, .failed:
break
default:
break
}
}

希望你能帮助我。

最佳答案

好吧,因为没有人回复。我认为框架中存在错误,因此经过一段时间的反复试验后,我将发布对我有用的内容。

let initialBounds = annotation.bounds
annotation.bounds = CGRect(
origin: locationOnPage,
size: initialBounds.size)
page.removeAnnotation(annotation)
page.addAnnotation(annotation)

它不优雅,但它完成了工作

关于swift - iOS 11 PDFKit 不更新注释位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46733741/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com