在UITabBarController中的子类QLPreviewController不显示PDF的编辑选项



我试图将QLPreviewController作为Tabview控制器中的选项卡之一。它能够正确显示PDF,但铅笔套件/标记不显示原因:我想显示PencilKit在PDF上绘制并保存它(来自本地或网络的其他类型的文件也因此QL),也从PDF(其他)捕获高光

Xcode 12.3斯威夫特5iOS/iPAD: 14

问题:无法在PDF文件停止处查看标记或编辑按钮。尝试隐藏选项卡栏和子视图总是nil。如有任何帮助,不胜感激。

Q2)是否有可能在菜单项中覆盖突出显示扇区/功能(在PDF上,我看到很好的选项,所以想使用它,但想保存文本选择)?

class QLPreviewController2: QLPreviewController {
var toolbars: [UIView] = []
var observations : [NSKeyValueObservation] = []
override func viewDidLoad() {
super.viewDidLoad()
delegate = self
}
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
}
override func viewDidLayoutSubviews() {
super.viewDidLayoutSubviews()
}
}
extension QLPreviewController2: QLPreviewControllerDelegate {

func previewController(_ controller: QLPreviewController, editingModeFor previewItem: QLPreviewItem) -> QLPreviewItemEditingMode {
return .updateContents
}
func previewController(_ controller: QLPreviewController, shouldOpen url: URL, for item: QLPreviewItem) -> Bool {
return true
}
func previewController(_ controller: QLPreviewController, didUpdateContentsOf previewItem: QLPreviewItem) {
}

func previewController(_: QLPreviewController, didSaveEditedCopyOf: QLPreviewItem, at: URL) {
}
}

TabVC是

class TabVC: UITabBarController, UITabBarControllerDelegate  {

override func viewDidLoad() {
super.viewDidLoad()
}

override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
guard let viewcontollers = viewControllers else {
return
}
let item1 = QLPreviewController2()
item1.dataSource = self
//        self.navigationItem.rightBarButtonItems?.append(item1.editButtonItem) //did not work
item1.isEditing = true //did not work
item1.setEditing(true, animated: true)//did not work
let icon1 = UITabBarItem(title: "Title", image: UIImage(named: "doc"), selectedImage: UIImage(named: "doc"))
item1.tabBarItem = icon1
self.viewControllers!.append(item1)
//        navigationItem.leftBarButtonItems?.append(item1.editButtonItem) //did not work
}
//Delegate methods
func tabBarController(_ tabBarController: UITabBarController, shouldSelect viewController: UIViewController) -> Bool {
print("Should select viewController: (viewController.title ?? "") ?")
return true;
}

}
extension TabVC: QLPreviewControllerDataSource {
func numberOfPreviewItems(in: QLPreviewController) -> Int {
return 1
}
func previewController(_ controller: QLPreviewController, previewItemAt index: Int) -> QLPreviewItem {
print("2")
let fileUrl = Bundle.main.url(forResource: "some", withExtension: ".pdf", subdirectory: nil, localization: nil)
let filePreview = PreviewItem2()
filePreview.previewItemURL = fileUrl
return filePreview
}
}

要解决第一个问题,您应该将QLPreviewController嵌入到UINavigationController中,这样就会显示UINavigationBarQLPreviewController上以及栏按钮项。然后,您必须将此UINavigationController实例附加到UITabBarControllerviewControllers实例属性。

override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
//...
let item1 = QLPreviewController2()
let nc = UINavigationController(rootViewController: item1)
//...
self.viewControllers!.append(nc)
}

第二个问题很难定义,因为你的英语,但我猜你想要一些自定义功能,QuickLook框架无法实现。

相关内容

  • 没有找到相关文章

最新更新