问题描述
我在我的应用程序中使用 QLPreviewController
并想要隐藏底部工具栏,它允许移动它的数据源项目。有可能以某种方式吗?
I use QLPreviewController
in my app and want to hide bottom toolbar which allows to move through it's datasource items. Is it possible to do somehow?
我试图将其作为子视图
搜索 QLPreviewController的视图
但它只有一个 _UISizeTrackingView
类的子视图。据我所知,这是一个私人课程,所以我没有权利寻找那里的东西。
I tried to search it as a subview
of QLPreviewController's view
but it has only one subview of _UISizeTrackingView
class . As i understand it's a private class so i have no rights to look for something there.
有没有办法隐藏这个工具栏,Apple是否允许这样做?谢谢。
Are there any ways to hide this toolbar and does Apple allow to make that? Thank you.
推荐答案
QLPreviewViewController
里面可以有1个以上的工具栏。这就是为什么你需要在子视图中找到所有 UIToolbar
并隐藏它们。
QLPreviewViewController
can have more than 1 toolbar inside. That's why you need to find all UIToolbar
in subviews and hide them.
此外,您需要观察隐藏
属性的更改,因为当用户点击 QLPreviewViewController
它改变工具栏和导航栏的可见性。
Also you need observe change of hidden
property because when user tap in QLPreviewViewController
it change visibility of toolbars and navigation bars.
Swift 3:
var toolbars: [UIToolbar] = []
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
toolbars = findToolbarsInSubviews(forView: view)
for toolbar in toolbars {
toolbar.isHidden = true
toolbar.addObserver(self, forKeyPath: "hidden", options: .new, context: nil)
}
}
override func viewWillDisappear(_ animated: Bool) {
super.viewWillDisappear(animated)
for toolbar in toolbars {
toolbar.removeObserver(self, forKeyPath: "hidden")
}
}
private func findToolbarsInSubviews(forView view: UIView) -> [UIToolbar] {
var toolbars: [UIToolbar] = []
for subview in view.subviews {
if subview is UIToolbar {
toolbars.append(subview as! UIToolbar)
}
toolbars.append(contentsOf: findToolbarsInSubviews(forView: subview))
}
return toolbars
}
override func observeValue(forKeyPath keyPath: String?, of object: Any?, change: [NSKeyValueChangeKey : Any]?, context: UnsafeMutableRawPointer?) {
if let keyPath = keyPath,
let toolbar = object as? UIToolbar,
let value = change?[.newKey] as? Bool,
keyPath == "hidden" && value == false {
toolbar.isHidden = true
}
}
这篇关于QLPreviewController隐藏底部工具栏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!