QLPreviewViewController
peut avoir plus d'une barre d'outils à l'intérieur. Pour cela, vous devez trouver tous les UIToolbar
dans les sous-visuels et les cacher.
De même, vous devez observer la propriété hidden
car lorsque l'utilisateur appuie sur QLPreviewViewController
, cela modifie la visibilité des barres d'outils et de navigation.
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
}
}
Avez-vous obtenu une solution pour ça? – Smita