【问题标题】:How to Subclass QLPreviewController and Disable Share button?如何继承 QLPreviewController 并禁用共享按钮?
【发布时间】:2017-09-23 05:26:21
【问题描述】:
  • 我已经完成了这样的代码,但它是开放的 QLPreviewController 但是 共享按钮未被禁用。我尝试了不同的东西,但它是 没用。

    - 或者您可以向我推荐任何其他可以禁用共享按钮的预览控制器。

  • qlViewController = QLPreviewController()

  • qlViewController.navigationItem.rightBarButtonItem = nil

  • qlViewController.delegate = self
  • qlViewController.dataSource = self

func numberOfPreviewItemsInPreviewController(控制器:QLPreviewController)-> Int { 返回 1 }

func previewController(controller: QLPreviewController, previewItemAtIndex index: Int) -> QLPreviewItem {
    controller.navigationItem.rightBarButtonItem = nil
    return fileUrlToOpen
}

【问题讨论】:

    标签: ios swift qlpreviewcontroller


    【解决方案1】:

    在 iOS 15 上测试,可能会随着下次更新而改变。

    QLPreviewController 现在嵌入了一个UINavigationController,然后它有一个根控制器和一个我们可以调整的标准navigationItem

    guard let navigationItem = (aQLPreviewController.children.first as? UINavigationController)?.viewControllers.first?.navigationItem else
    {
        // Not iOS 15 or the QLPreviewController implementation has changed
        return
    }
    
    // Do whatever you want with the navigationItem
    navigationItem.rightBarButtonItem?.isEnabled = false
    // or navigationItem.rightBarButtonItem = nil
    

    【讨论】:

      【解决方案2】:

      UPD:这不再起作用了

      有一个如何隐藏右侧分享按钮的例子

      final class AttachmentQuickLookVC: QLPreviewController {
          
          override func viewWillLayoutSubviews() {
              super.viewWillLayoutSubviews()
              self.navigationItem.rightBarButtonItems = [UIBarButtonItem]()        
          }
      }
      

      另外,如果你想自定义后退按钮,你可以这样做:

      final class AttachmentQuickLookVC: QLPreviewController {
          
          override func viewWillLayoutSubviews() {
              super.viewWillLayoutSubviews()        
              let backButton = UIButton(frame: CGRect(x: 0, y: 0, width: 100, height: 35))
              
              backButton.contentEdgeInsets = UIEdgeInsets(top: 0, left: 0, bottom: 0, right: 0)
              backButton.contentHorizontalAlignment = .left
              backButton.setImage(UIImage(named: "ic_back"), for: .normal)
      
              let barButton = UIBarButtonItem(customView: backButton)
              self.navigationItem.leftBarButtonItems = [barButton]
              self.navigationItem.hidesBackButton = true
          }
      }
      

      【讨论】:

      • 不适合我。按钮仍显示在右上角。
      • @zumzum 很好,它在发布时有效。所以,如果系统改变了,你找到了更新的解决方案,请提供它。
      • 根本无法修改QLPreviewControllers的导航项
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-10-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-07-20
      • 1970-01-01
      相关资源
      最近更新 更多