首页 > 解决方案 > PDFKit 无法在 iOS 13 和 iPhone 11、XR 等上绘制图像注释

问题描述

我被分配了一个任务,我应该在这些图像之间绘制一些图像和一些直线。我用这个方法成功地做到了,

    class PDFImageAnnotation: PDFAnnotation {

    var image: UIImage?

    convenience init(_ image: UIImage?, bounds: CGRect, properties: [AnyHashable : Any]?) {
        self.init(bounds: bounds, forType: PDFAnnotationSubtype.ink, withProperties: properties)
        self.image = image
    }

    override func draw(with box: PDFDisplayBox, in context: CGContext) {
        super.draw(with: box, in: context)

        // Drawing the image within the annotation's bounds.
        guard let cgImage = image?.cgImage else { return }
        context.draw(cgImage, in: bounds)
    }
}

现在,每当用户点击 PDF 页面时,我只需在该位置添加此图像注释。在 iOS 13 发布后,每当我点击 PDF 页面时,都不会显示图像注释,尽管我收到了触摸代表并且我的代码在 iOS 12 上运行良好。任何可能的解决方案?

标签: swiftpdfannotationsios13ios-pdfkit

解决方案


我遇到了类似的问题,点击手势没有添加到PDFView上。这可能是因为视图堆叠,我不确定。但我通过在我的PDFView顶部添加另一个UIView并在其上添加轻击手势来解决它。


推荐阅读