marinofaggiana 5 سال پیش
والد
کامیت
8ace7eaeca
2فایلهای تغییر یافته به همراه45 افزوده شده و 14 حذف شده
  1. 1 1
      iOSClient/Main/NCDetailViewController.swift
  2. 44 13
      iOSClient/Viewer/NCViewerPDF.swift

+ 1 - 1
iOSClient/Main/NCDetailViewController.swift

@@ -266,7 +266,7 @@ class NCDetailViewController: UIViewController {
                         return
                     }
                     
-                    viewerPDF.setupPdfView(filePath: URL(fileURLWithPath: filePath), view: backgroundView)
+                    viewerPDF.setupPdfView(filePath: URL(fileURLWithPath: filePath), detailViewController: self)
                 }
                 
                 return

+ 44 - 13
iOSClient/Viewer/NCViewerPDF.swift

@@ -29,6 +29,8 @@ import PDFKit
 @objc class NCViewerPDF: PDFView {
     
     private var thumbnailViewHeight: CGFloat = 48
+    private var detailViewController: NCDetailViewController?
+    private var pdfThumbnailView: PDFThumbnailView?
 
     required init?(coder: NSCoder) {
         super.init(coder: coder)
@@ -43,9 +45,10 @@ import PDFKit
         backgroundColor = NCBrandColor.sharedInstance.backgroundView
     }
     
-    @objc func setupPdfView(filePath: URL, view: UIView) {
+    @objc func setupPdfView(filePath: URL, detailViewController: NCDetailViewController) {
+        self.detailViewController = detailViewController
         
-        guard let pdfDocument = PDFDocument(url: filePath) else {return}
+        guard let pdfDocument = PDFDocument(url: filePath) else { return }
         
         document = pdfDocument
         backgroundColor = NCBrandColor.sharedInstance.backgroundView
@@ -55,21 +58,49 @@ import PDFKit
         autoresizingMask = [.flexibleWidth, .flexibleHeight, .flexibleTopMargin, .flexibleBottomMargin]
         usePageViewController(true, withViewOptions: nil)
         
-        view.addSubview(self)
+        detailViewController.backgroundView.addSubview(self)
         
-        let pdfThumbnailView = PDFThumbnailView()
-        pdfThumbnailView.translatesAutoresizingMaskIntoConstraints = false
-        pdfThumbnailView.pdfView = self
-        pdfThumbnailView.layoutMode = .horizontal
-        pdfThumbnailView.thumbnailSize = CGSize(width: 40, height: thumbnailViewHeight - 2)
+        pdfThumbnailView = PDFThumbnailView()
+        pdfThumbnailView!.translatesAutoresizingMaskIntoConstraints = false
+        pdfThumbnailView!.pdfView = self
+        pdfThumbnailView!.layoutMode = .horizontal
+        pdfThumbnailView!.thumbnailSize = CGSize(width: 40, height: thumbnailViewHeight - 2)
         //pdfThumbnailView.layer.shadowOffset.height = -5
         //pdfThumbnailView.layer.shadowOpacity = 0.25
         
-        view.addSubview(pdfThumbnailView)
+        detailViewController.backgroundView.addSubview(pdfThumbnailView!)
         
-        pdfThumbnailView.heightAnchor.constraint(equalToConstant: thumbnailViewHeight).isActive = true
-        pdfThumbnailView.leadingAnchor.constraint(equalTo: view.safeAreaLayoutGuide.leadingAnchor).isActive = true
-        pdfThumbnailView.trailingAnchor.constraint(equalTo: view.safeAreaLayoutGuide.trailingAnchor).isActive = true
-        pdfThumbnailView.bottomAnchor.constraint(equalTo: view.safeAreaLayoutGuide.bottomAnchor).isActive = true
+        pdfThumbnailView!.heightAnchor.constraint(equalToConstant: thumbnailViewHeight).isActive = true
+        pdfThumbnailView!.leadingAnchor.constraint(equalTo: detailViewController.backgroundView.safeAreaLayoutGuide.leadingAnchor).isActive = true
+        pdfThumbnailView!.trailingAnchor.constraint(equalTo: detailViewController.backgroundView.safeAreaLayoutGuide.trailingAnchor).isActive = true
+        pdfThumbnailView!.bottomAnchor.constraint(equalTo: detailViewController.backgroundView.safeAreaLayoutGuide.bottomAnchor).isActive = true
+        
+        let tapGesture = UITapGestureRecognizer(target: self, action: #selector(didTap(_:)))
+        tapGesture.numberOfTapsRequired = 1
+        
+        if var recognizer = self.gestureRecognizers {
+            recognizer.append(tapGesture)
+            self.gestureRecognizers = recognizer
+        }
+    }
+    
+    @objc func didTap(_ recognizer: UITapGestureRecognizer) {
+        guard let detailViewController = self.detailViewController else { return }
+        guard let navigationController = detailViewController.navigationController else { return }
+        
+        if navigationController.isNavigationBarHidden {
+            navigationController.isNavigationBarHidden = false
+            pdfThumbnailView!.isHidden = false
+            detailViewController.view.backgroundColor = NCBrandColor.sharedInstance.backgroundView
+            backgroundColor = NCBrandColor.sharedInstance.backgroundView
+            self.frame = CGRect(x: 0, y: 0, width: detailViewController.backgroundView.frame.width, height: detailViewController.backgroundView.frame.height - thumbnailViewHeight)
+        } else {
+            navigationController.isNavigationBarHidden = true
+            pdfThumbnailView!.isHidden = true
+            detailViewController.view.backgroundColor = .black
+            backgroundColor = .black
+            self.frame = CGRect(x: 0, y: 0, width: detailViewController.backgroundView.frame.width, height: detailViewController.backgroundView.frame.height)
+        }
     }
+
 }