You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Swift PDFKit如何将注释添加到页面注释数组的开头?

Swift PDFKit:将注释添加到页面注释数组开头的解决方案

可以通过以下方法实现将图片注释添加到页面注释数组开头,让它处于底层,不遮挡其他可编辑注释:

  1. 获取页面当前的注释数组
  2. 将你的图片注释插入到数组的首位
  3. 调用setAnnotations(_:)方法重新设置页面的注释数组

代码示例:

// 假设已创建好图片注释 myImageAnnotation
if var existingAnnotations = page.annotations {
    // 插入到数组开头
    existingAnnotations.insert(myImageAnnotation, at: 0)
    // 重新设置注释数组
    page.setAnnotations(existingAnnotations)
} else {
    // 页面无现有注释时直接设置
    page.setAnnotations([myImageAnnotation])
}

原理说明:PDFKit的addAnnotation(_:)默认会把注释追加到数组末尾(对应显示层级的最上层),而注释数组的顺序直接决定了显示层级——数组靠前的注释显示在底层,靠后的显示在上方。通过手动调整数组顺序再替换,就能实现让图片注释处于底层,其他可编辑注释显示在它上方的需求。

内容的提问来源于stack exchange,提问作者micah

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.09 13:31:03