Phi*_*hil 7 ios swift ios-pdfkit ios16
我正在使用 PDFKit 渲染 PDF,并使用“UIMenuController”添加了自定义菜单。但现在从 iOS 16 开始已弃用。
\n我使用以下代码删除 share\xe3\x80\x81lookup 菜单项:
\n@available(iOS 13.0, *)\nopen override func buildMenu(with builder: UIMenuBuilder) {\n builder.remove(menu: .lookup)\n builder.remove(menu: .share)\n builder.remove(menu: .replace)\n super.buildMenu(with: builder)\n}\nRun Code Online (Sandbox Code Playgroud)\n但是,当用户长按选择 PDF 中的文本时,无法删除“突出显示”上下文菜单。有没有办法摆脱这个菜单项?以及如何在 PDFView 中使用 UIEditMenuInteraction ?
\n任何帮助将非常感激。
\n小智 1
使用UIContextMenuInteractioniOS 13 以来可用的功能:
import PDFKit
class ViewController: UIViewController, UIContextMenuInteractionDelegate {
// ...
override func viewDidLoad() {
super.viewDidLoad()
// Set up the UIContextMenuInteraction for your PDFView
let interaction = UIContextMenuInteraction(delegate: self)
pdfView.addInteraction(interaction)
}
// Implement the UIContextMenuInteractionDelegate method
func contextMenuInteraction(_ interaction: UIContextMenuInteraction, configurationForMenuAtLocation location: CGPoint) -> UIContextMenuConfiguration? {
return UIContextMenuConfiguration(identifier: nil, previewProvider: nil) { _ in
// Create an empty UIMenu
return UIMenu(title: "", children: [])
}
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
854 次 |
| 最近记录: |