[英]How to hide action/share button from QLPreviewController Xamarin iOS 10?
[英]hide share button from QLPreviewController
我需要从 QLPreviewController 隐藏共享按钮按钮
这是将 PDF (例如)显示到新视图中的原始代码
var previewItem = NSURL()
func preview(_command: CDVInvokedUrlCommand){
self.previewItem = fileLocationURL! as NSURL
let previewController = QLPreviewController();
previewController.dataSource = self;
self.viewController?.present(previewController, animated: true, completion: nil);
}
extension PreviewAnyFile: QLPreviewControllerDataSource {
func numberOfPreviewItems(in controller: QLPreviewController) -> Int {
return 1
}
func previewController(_ controller: QLPreviewController, previewItemAt index: Int) -> QLPreviewItem {
return self.previewItem as QLPreviewItem
}
}
我尝试了这段代码(将 QLPreviewController 超类到 QLPreviewController 中)但共享按钮仍然存在
class QLSPreviewController : QLPreviewController {
override func viewDidLoad() {
super.viewDidLoad()
}
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
}
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(true )
//This hides the share item
if let add = self.children.first as? UINavigationController {
if let layoutContainerView = add.view.subviews[1] as? UINavigationBar {
layoutContainerView.subviews[2].subviews[1].isHidden = true
}
}
}
}
基于几个合理安全的假设:
你应该能够删除 UBarButtonItem
从 ViewDidLoad 内部:
navigationItem.rightBarButtonItems = []
或从 class 外部(如果需要):
myPDFViewController.navigationItem.rightBarButtonItems = []
子类化 QLPreviewController 并覆盖viewWillLayoutSubviews
:
class PicturePreviewViewController: QLPreviewController {
override func viewWillLayoutSubviews() {
super.viewWillLayoutSubviews()
// Hide share button.
if let navigationController = children.first as? UINavigationController,
let shareItem = navigationController.toolbar.items?.first as? UIBarButtonItem {
shareItem.isEnabled = false
shareItem.tintColor = .clear
}
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.