How to hide share button in QLPreviewController using swift?

前端 未结 7 2093
无人共我
无人共我 2021-01-06 02:40

I\'m using the below code to use QLPreviewcontroller to show some documents in my app,

let ql = QLPreviewController()
ql.dataSource = self
//ql.navigationIte         


        
7条回答
  •  抹茶落季
    2021-01-06 03:04

    1. Create a subclass of QLPreviewController

    2. Add the following code to it

    Swift:

    var toolbars: [UIView] = []
    
    var observations : [NSKeyValueObservation] = []
    
        override func viewDidLoad() {
            super.viewDidLoad()
    
            navigationItem.setRightBarButton(UIBarButtonItem(), animated: false)
    
        }
    
        override func viewWillAppear(_ animated: Bool) {
            super.viewWillAppear(animated)
    
            navigationController?.toolbar.isHidden = true
    
            if let navigationToobar = navigationController?.toolbar {
                let observation = navigationToobar.observe(\.isHidden) {[weak self] (changedToolBar, change) in
    
                    if self?.navigationController?.toolbar.isHidden == false {
                         self?.navigationController?.toolbar.isHidden = true
                    }
                }
                observations.append(observation)
            }
    
            toolbars = toolbarsInSubviews(forView: view)
    
            for toolbar in toolbars {
    
                toolbar.isHidden = true
    
                let observation = toolbar.observe(\.isHidden) { (changedToolBar, change) in
                    if let isHidden = change.newValue,
                        isHidden == false {
                        changedToolBar.isHidden = true
                    }
                }
    
                observations.append(observation)
            }
        }
    
        private func toolbarsInSubviews(forView view: UIView) -> [UIView] {
    
            var toolbars: [UIView] = []
    
            for subview in view.subviews {
                if subview is UIToolbar {
                    toolbars.append(subview)
                }
                toolbars.append(contentsOf: toolbarsInSubviews(forView: subview))
            }
            return toolbars
        }
    

提交回复
热议问题