|
@@ -23,21 +23,34 @@
|
|
|
|
|
|
import UIKit
|
|
|
import PDFKit
|
|
|
+import EasyTipView
|
|
|
|
|
|
-class NCViewerPDF: UIViewController, NCViewerPDFSearchDelegate {
|
|
|
+class NCViewerPDF: UIViewController, NCViewerPDFSearchDelegate, UIGestureRecognizerDelegate {
|
|
|
|
|
|
- let appDelegate = UIApplication.shared.delegate as! AppDelegate
|
|
|
var metadata = tableMetadata()
|
|
|
var imageIcon: UIImage?
|
|
|
|
|
|
+ private var filePath = ""
|
|
|
+
|
|
|
private var pdfView = PDFView()
|
|
|
- private var thumbnailViewHeight: CGFloat = 40
|
|
|
+ private var pdfThumbnailScrollView = UIScrollView()
|
|
|
private var pdfThumbnailView = PDFThumbnailView()
|
|
|
private var pdfDocument: PDFDocument?
|
|
|
private let pageView = UIView()
|
|
|
private let pageViewLabel = UILabel()
|
|
|
+ private var tipView: EasyTipView?
|
|
|
+
|
|
|
+ private let thumbnailViewHeight: CGFloat = 70
|
|
|
+ private let thumbnailViewWidth: CGFloat = 80
|
|
|
+ private let thumbnailPadding: CGFloat = 2
|
|
|
+ private let animateDuration: TimeInterval = 0.3
|
|
|
+
|
|
|
+ private var defaultBackgroundColor: UIColor = .clear
|
|
|
+
|
|
|
+ private var pdfThumbnailScrollViewTopAnchor: NSLayoutConstraint?
|
|
|
+ private var pdfThumbnailScrollViewTrailingAnchor: NSLayoutConstraint?
|
|
|
+ private var pdfThumbnailScrollViewWidthAnchor: NSLayoutConstraint?
|
|
|
private var pageViewWidthAnchor: NSLayoutConstraint?
|
|
|
- private var filePath = ""
|
|
|
|
|
|
// MARK: - View Life Cycle
|
|
|
|
|
@@ -48,80 +61,129 @@ class NCViewerPDF: UIViewController, NCViewerPDFSearchDelegate {
|
|
|
override func viewDidLoad() {
|
|
|
|
|
|
filePath = CCUtility.getDirectoryProviderStorageOcId(metadata.ocId, fileNameView: metadata.fileNameView)!
|
|
|
-
|
|
|
- pdfView = PDFView(frame: CGRect(x: 0, y: 0, width: view.frame.width, height: view.frame.height))
|
|
|
pdfDocument = PDFDocument(url: URL(fileURLWithPath: filePath))
|
|
|
+ let pageCount = CGFloat(pdfDocument?.pageCount ?? 0)
|
|
|
+ defaultBackgroundColor = pdfView.backgroundColor
|
|
|
+ view.backgroundColor = defaultBackgroundColor
|
|
|
+
|
|
|
+ navigationItem.rightBarButtonItem = UIBarButtonItem(image: UIImage(named: "more")!.image(color: NCBrandColor.shared.label, size: 25), style: .plain, target: self, action: #selector(self.openMenuMore))
|
|
|
+ navigationItem.title = metadata.fileNameView
|
|
|
+
|
|
|
+ // PDF VIEW
|
|
|
|
|
|
+ if UIDevice.current.userInterfaceIdiom == .phone {
|
|
|
+ pdfView = PDFView(frame: CGRect(x: 0, y: 0, width: view.frame.width, height: view.frame.height))
|
|
|
+ } else {
|
|
|
+ pdfView = PDFView(frame: CGRect(x: 0, y: 0, width: view.frame.width-thumbnailViewWidth, height: view.frame.height))
|
|
|
+ }
|
|
|
+ pdfView.autoresizingMask = [.flexibleWidth, .flexibleHeight, .flexibleTopMargin, .flexibleLeftMargin]
|
|
|
pdfView.document = pdfDocument
|
|
|
- pdfView.backgroundColor = NCBrandColor.shared.systemBackground
|
|
|
- pdfView.displayMode = .singlePageContinuous
|
|
|
pdfView.autoScales = true
|
|
|
- pdfView.displayDirection = CCUtility.getPDFDisplayDirection()
|
|
|
- pdfView.autoresizingMask = [.flexibleWidth, .flexibleHeight, .flexibleTopMargin, .flexibleBottomMargin]
|
|
|
- pdfView.usePageViewController(true, withViewOptions: nil)
|
|
|
-
|
|
|
+ pdfView.displayMode = .singlePageContinuous
|
|
|
+ pdfView.displayDirection = .vertical
|
|
|
+ pdfView.maxScaleFactor = 4.0
|
|
|
+ pdfView.minScaleFactor = pdfView.scaleFactorForSizeToFit
|
|
|
view.addSubview(pdfView)
|
|
|
|
|
|
+ // PDF THUMBNAIL
|
|
|
+
|
|
|
+ pdfThumbnailScrollView.translatesAutoresizingMaskIntoConstraints = false
|
|
|
+ pdfThumbnailScrollView.backgroundColor = defaultBackgroundColor
|
|
|
+ pdfThumbnailScrollView.showsVerticalScrollIndicator = false
|
|
|
+ view.addSubview(pdfThumbnailScrollView)
|
|
|
+
|
|
|
+ pdfThumbnailScrollView.bottomAnchor.constraint(equalTo: view.bottomAnchor).isActive = true
|
|
|
+ pdfThumbnailScrollViewTopAnchor = pdfThumbnailScrollView.topAnchor.constraint(equalTo: view.safeAreaLayoutGuide.topAnchor)
|
|
|
+ pdfThumbnailScrollViewTopAnchor?.isActive = true
|
|
|
+ pdfThumbnailScrollViewTrailingAnchor = pdfThumbnailScrollView.trailingAnchor.constraint(equalTo: view.trailingAnchor)
|
|
|
+ pdfThumbnailScrollViewTrailingAnchor?.isActive = true
|
|
|
+ pdfThumbnailScrollViewWidthAnchor = pdfThumbnailScrollView.widthAnchor.constraint(equalToConstant: thumbnailViewWidth)
|
|
|
+ pdfThumbnailScrollViewWidthAnchor?.isActive = true
|
|
|
+
|
|
|
pdfThumbnailView.translatesAutoresizingMaskIntoConstraints = false
|
|
|
pdfThumbnailView.pdfView = pdfView
|
|
|
- pdfThumbnailView.layoutMode = .horizontal
|
|
|
- pdfThumbnailView.thumbnailSize = CGSize(width: 40, height: thumbnailViewHeight)
|
|
|
+ pdfThumbnailView.layoutMode = .vertical
|
|
|
+ pdfThumbnailView.thumbnailSize = CGSize(width: thumbnailViewHeight, height: thumbnailViewHeight)
|
|
|
pdfThumbnailView.backgroundColor = .clear
|
|
|
- // pdfThumbnailView.layer.shadowOffset.height = -5
|
|
|
- // pdfThumbnailView.layer.shadowOpacity = 0.25
|
|
|
-
|
|
|
- view.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
|
|
|
+ if UIDevice.current.userInterfaceIdiom == .phone {
|
|
|
+ self.pdfThumbnailScrollView.isHidden = true
|
|
|
+ } else {
|
|
|
+ self.pdfThumbnailScrollView.isHidden = false
|
|
|
+ }
|
|
|
+ pdfThumbnailScrollView.addSubview(pdfThumbnailView)
|
|
|
+
|
|
|
+ NSLayoutConstraint.activate([
|
|
|
+ pdfThumbnailView.topAnchor.constraint(equalTo: pdfThumbnailScrollView.topAnchor),
|
|
|
+ pdfThumbnailView.bottomAnchor.constraint(equalTo: pdfThumbnailScrollView.bottomAnchor),
|
|
|
+ pdfThumbnailView.leadingAnchor.constraint(equalTo: pdfThumbnailScrollView.leadingAnchor),
|
|
|
+ pdfThumbnailView.leadingAnchor.constraint(equalTo: pdfThumbnailScrollView.trailingAnchor, constant: (UIApplication.shared.keyWindow?.safeAreaInsets.left ?? 0)),
|
|
|
+ pdfThumbnailView.widthAnchor.constraint(equalToConstant: thumbnailViewWidth)
|
|
|
+ ])
|
|
|
+ let contentViewCenterY = pdfThumbnailView.centerYAnchor.constraint(equalTo: pdfThumbnailScrollView.centerYAnchor)
|
|
|
+ contentViewCenterY.priority = .defaultLow
|
|
|
+ let contentViewHeight = pdfThumbnailView.heightAnchor.constraint(equalToConstant: CGFloat(pageCount * thumbnailViewHeight) + CGFloat(pageCount * thumbnailPadding) + 30)
|
|
|
+ contentViewHeight.priority = .defaultLow
|
|
|
+ NSLayoutConstraint.activate([
|
|
|
+ contentViewCenterY,
|
|
|
+ contentViewHeight
|
|
|
+ ])
|
|
|
+
|
|
|
+ // COUNTER PDF PAGE VIEW
|
|
|
|
|
|
pageView.translatesAutoresizingMaskIntoConstraints = false
|
|
|
pageView.layer.cornerRadius = 10
|
|
|
pageView.backgroundColor = NCBrandColor.shared.systemBackground.withAlphaComponent(
|
|
|
UIAccessibility.isReduceTransparencyEnabled ? 1 : 0.5
|
|
|
)
|
|
|
-
|
|
|
view.addSubview(pageView)
|
|
|
|
|
|
- pageView.heightAnchor.constraint(equalToConstant: 30).isActive = true
|
|
|
+ NSLayoutConstraint.activate([
|
|
|
+ pageView.topAnchor.constraint(equalTo: view.safeAreaLayoutGuide.topAnchor, constant: 10),
|
|
|
+ pageView.heightAnchor.constraint(equalToConstant: 30),
|
|
|
+ pageView.leftAnchor.constraint(equalTo: view.safeAreaLayoutGuide.leftAnchor, constant: 10)
|
|
|
+ ])
|
|
|
pageViewWidthAnchor = pageView.widthAnchor.constraint(equalToConstant: 10)
|
|
|
pageViewWidthAnchor?.isActive = true
|
|
|
- pageView.topAnchor.constraint(equalTo: view.safeAreaLayoutGuide.topAnchor, constant: 4).isActive = true
|
|
|
- pageView.leftAnchor.constraint(equalTo: view.safeAreaLayoutGuide.leftAnchor, constant: 7).isActive = true
|
|
|
|
|
|
pageViewLabel.translatesAutoresizingMaskIntoConstraints = false
|
|
|
pageViewLabel.textAlignment = .center
|
|
|
pageViewLabel.textColor = NCBrandColor.shared.label
|
|
|
-
|
|
|
pageView.addSubview(pageViewLabel)
|
|
|
|
|
|
- pageViewLabel.leftAnchor.constraint(equalTo: pageView.leftAnchor).isActive = true
|
|
|
- pageViewLabel.rightAnchor.constraint(equalTo: pageView.rightAnchor).isActive = true
|
|
|
- pageViewLabel.topAnchor.constraint(equalTo: pageView.topAnchor).isActive = true
|
|
|
- pageViewLabel.bottomAnchor.constraint(equalTo: pageView.bottomAnchor).isActive = true
|
|
|
+ NSLayoutConstraint.activate([
|
|
|
+ pageViewLabel.topAnchor.constraint(equalTo: pageView.topAnchor),
|
|
|
+ pageViewLabel.leftAnchor.constraint(equalTo: pageView.leftAnchor),
|
|
|
+ pageViewLabel.rightAnchor.constraint(equalTo: pageView.rightAnchor),
|
|
|
+ pageViewLabel.bottomAnchor.constraint(equalTo: pageView.bottomAnchor)
|
|
|
+ ])
|
|
|
|
|
|
- pdfView.backgroundColor = NCBrandColor.shared.systemBackground
|
|
|
- pdfView.layoutIfNeeded()
|
|
|
- handlePageChange()
|
|
|
+ // GESTURE
|
|
|
|
|
|
- let tapGesture = UITapGestureRecognizer(target: self, action: #selector(didTap(_:)))
|
|
|
- tapGesture.numberOfTapsRequired = 1
|
|
|
- pdfView.addGestureRecognizer(tapGesture)
|
|
|
+ let tapPdfView = UITapGestureRecognizer(target: self, action: #selector(tapPdfView))
|
|
|
+ tapPdfView.numberOfTapsRequired = 1
|
|
|
+ pdfView.addGestureRecognizer(tapPdfView)
|
|
|
|
|
|
// recognize single / double tap
|
|
|
for gesture in pdfView.gestureRecognizers! {
|
|
|
- tapGesture.require(toFail: gesture)
|
|
|
+ tapPdfView.require(toFail: gesture)
|
|
|
}
|
|
|
- }
|
|
|
|
|
|
- override func viewWillAppear(_ animated: Bool) {
|
|
|
- super.viewWillAppear(animated)
|
|
|
+ let swipePdfView = UISwipeGestureRecognizer(target: self, action: #selector(gestureClosePdfThumbnail))
|
|
|
+ swipePdfView.direction = .right
|
|
|
+ pdfView.addGestureRecognizer(swipePdfView)
|
|
|
|
|
|
- appDelegate.activeViewController = self
|
|
|
+ let swipePdfThumbnailScrollView = UISwipeGestureRecognizer(target: self, action: #selector(gestureClosePdfThumbnail))
|
|
|
+ swipePdfThumbnailScrollView.direction = .right
|
|
|
+ pdfThumbnailScrollView.addGestureRecognizer(swipePdfThumbnailScrollView)
|
|
|
+
|
|
|
+ let edgePdfView = UIScreenEdgePanGestureRecognizer(target: self, action: #selector(gestureOpenPdfThumbnail))
|
|
|
+ edgePdfView.edges = .right
|
|
|
+ pdfView.addGestureRecognizer(edgePdfView)
|
|
|
+
|
|
|
+ let edgeView = UIScreenEdgePanGestureRecognizer(target: self, action: #selector(gestureOpenPdfThumbnail))
|
|
|
+ edgeView.edges = .right
|
|
|
+ view.addGestureRecognizer(edgeView)
|
|
|
|
|
|
- //
|
|
|
NotificationCenter.default.addObserver(self, selector: #selector(favoriteFile(_:)), name: NSNotification.Name(rawValue: NCGlobal.shared.notificationCenterFavoriteFile), object: nil)
|
|
|
NotificationCenter.default.addObserver(self, selector: #selector(deleteFile(_:)), name: NSNotification.Name(rawValue: NCGlobal.shared.notificationCenterDeleteFile), object: nil)
|
|
|
NotificationCenter.default.addObserver(self, selector: #selector(renameFile(_:)), name: NSNotification.Name(rawValue: NCGlobal.shared.notificationCenterRenameFile), object: nil)
|
|
@@ -130,19 +192,62 @@ class NCViewerPDF: UIViewController, NCViewerPDFSearchDelegate {
|
|
|
|
|
|
NotificationCenter.default.addObserver(self, selector: #selector(viewUnload), name: NSNotification.Name(rawValue: NCGlobal.shared.notificationCenterMenuDetailClose), object: nil)
|
|
|
NotificationCenter.default.addObserver(self, selector: #selector(searchText), name: NSNotification.Name(rawValue: NCGlobal.shared.notificationCenterMenuSearchTextPDF), object: nil)
|
|
|
- NotificationCenter.default.addObserver(self, selector: #selector(direction(_:)), name: NSNotification.Name(rawValue: NCGlobal.shared.notificationCenterMenuPDFDisplayDirection), object: nil)
|
|
|
NotificationCenter.default.addObserver(self, selector: #selector(goToPage), name: NSNotification.Name(rawValue: NCGlobal.shared.notificationCenterMenuGotToPageInPDF), object: nil)
|
|
|
+
|
|
|
NotificationCenter.default.addObserver(self, selector: #selector(handlePageChange), name: Notification.Name.PDFViewPageChanged, object: nil)
|
|
|
|
|
|
- //
|
|
|
- navigationItem.rightBarButtonItem = UIBarButtonItem(image: UIImage(named: "more")!.image(color: NCBrandColor.shared.label, size: 25), style: .plain, target: self, action: #selector(self.openMenuMore))
|
|
|
+ // Tip
|
|
|
+ if UIDevice.current.userInterfaceIdiom == .phone && !NCManageDatabase.shared.tipExists(NCGlobal.shared.tipNCViewerPDFThumbnail){
|
|
|
|
|
|
- navigationController?.navigationBar.prefersLargeTitles = true
|
|
|
- navigationItem.title = metadata.fileNameView
|
|
|
+ var preferences = EasyTipView.Preferences()
|
|
|
+ preferences.drawing.foregroundColor = NCBrandColor.shared.brandText
|
|
|
+ preferences.drawing.backgroundColor = NCBrandColor.shared.customer
|
|
|
+ preferences.drawing.textAlignment = .left
|
|
|
+ preferences.drawing.arrowPosition = .right
|
|
|
+ preferences.drawing.cornerRadius = 10
|
|
|
+
|
|
|
+ preferences.positioning.bubbleInsets.right = UIApplication.shared.keyWindow?.safeAreaInsets.right ?? 0
|
|
|
+
|
|
|
+ preferences.animating.dismissTransform = CGAffineTransform(translationX: 0, y: 100)
|
|
|
+ preferences.animating.showInitialTransform = CGAffineTransform(translationX: 0, y: -100)
|
|
|
+ preferences.animating.showInitialAlpha = 0
|
|
|
+ preferences.animating.showDuration = 1.5
|
|
|
+ preferences.animating.dismissDuration = 1.5
|
|
|
+
|
|
|
+ tipView = EasyTipView(text: NSLocalizedString("_tip_pdf_thumbnails_", comment: ""), preferences: preferences, delegate: self)
|
|
|
+ }
|
|
|
+
|
|
|
+ setConstraints()
|
|
|
+ handlePageChange()
|
|
|
+ }
|
|
|
+
|
|
|
+ override func viewDidAppear(_ animated: Bool) {
|
|
|
+ super.viewDidAppear(animated)
|
|
|
+
|
|
|
+ self.tipView?.show(forView: self.pdfThumbnailScrollView, withinSuperview: self.view)
|
|
|
}
|
|
|
|
|
|
- override func viewWillDisappear(_ animated: Bool) {
|
|
|
- super.viewWillDisappear(animated)
|
|
|
+ @objc func viewUnload() {
|
|
|
+
|
|
|
+ navigationController?.popViewController(animated: true)
|
|
|
+ }
|
|
|
+
|
|
|
+ override func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator) {
|
|
|
+ super.viewWillTransition(to: size, with: coordinator)
|
|
|
+
|
|
|
+ coordinator.animate(alongsideTransition: { context in
|
|
|
+ if UIDevice.current.userInterfaceIdiom == .phone {
|
|
|
+ // Close
|
|
|
+ self.tipView?.dismiss()
|
|
|
+ self.pdfThumbnailScrollViewTrailingAnchor?.constant = self.thumbnailViewWidth + (UIApplication.shared.keyWindow?.safeAreaInsets.right ?? 0)
|
|
|
+ self.pdfThumbnailScrollView.isHidden = true
|
|
|
+ }
|
|
|
+ }, completion: { context in
|
|
|
+ self.setConstraints()
|
|
|
+ })
|
|
|
+ }
|
|
|
+
|
|
|
+ deinit {
|
|
|
|
|
|
NotificationCenter.default.removeObserver(self, name: NSNotification.Name(rawValue: NCGlobal.shared.notificationCenterFavoriteFile), object: nil)
|
|
|
NotificationCenter.default.removeObserver(self, name: NSNotification.Name(rawValue: NCGlobal.shared.notificationCenterDeleteFile), object: nil)
|
|
@@ -152,17 +257,11 @@ class NCViewerPDF: UIViewController, NCViewerPDFSearchDelegate {
|
|
|
|
|
|
NotificationCenter.default.removeObserver(self, name: NSNotification.Name(rawValue: NCGlobal.shared.notificationCenterMenuDetailClose), object: nil)
|
|
|
NotificationCenter.default.removeObserver(self, name: NSNotification.Name(rawValue: NCGlobal.shared.notificationCenterMenuSearchTextPDF), object: nil)
|
|
|
- NotificationCenter.default.removeObserver(self, name: NSNotification.Name(rawValue: NCGlobal.shared.notificationCenterMenuPDFDisplayDirection), object: nil)
|
|
|
NotificationCenter.default.removeObserver(self, name: NSNotification.Name(rawValue: NCGlobal.shared.notificationCenterMenuGotToPageInPDF), object: nil)
|
|
|
|
|
|
NotificationCenter.default.removeObserver(self, name: Notification.Name.PDFViewPageChanged, object: nil)
|
|
|
}
|
|
|
|
|
|
- @objc func viewUnload() {
|
|
|
-
|
|
|
- navigationController?.popViewController(animated: true)
|
|
|
- }
|
|
|
-
|
|
|
// MARK: - NotificationCenter
|
|
|
|
|
|
@objc func uploadedFile(_ notification: NSNotification) {
|
|
@@ -236,17 +335,6 @@ class NCViewerPDF: UIViewController, NCViewerPDFSearchDelegate {
|
|
|
self.present(navigaionController, animated: true)
|
|
|
}
|
|
|
|
|
|
- @objc func direction(_ notification: NSNotification) {
|
|
|
-
|
|
|
- if let userInfo = notification.userInfo as NSDictionary? {
|
|
|
- if let direction = userInfo["direction"] as? PDFDisplayDirection {
|
|
|
- pdfView.displayDirection = direction
|
|
|
- CCUtility.setPDFDisplayDirection(direction)
|
|
|
- handlePageChange()
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
@objc func goToPage() {
|
|
|
|
|
|
guard let pdfDocument = pdfView.document else { return }
|
|
@@ -272,45 +360,112 @@ class NCViewerPDF: UIViewController, NCViewerPDFSearchDelegate {
|
|
|
// MARK: - Action
|
|
|
|
|
|
@objc func openMenuMore() {
|
|
|
+
|
|
|
if imageIcon == nil { imageIcon = UIImage(named: "file_pdf") }
|
|
|
NCViewer.shared.toggleMenu(viewController: self, metadata: metadata, webView: false, imageIcon: imageIcon)
|
|
|
}
|
|
|
|
|
|
// MARK: - Gesture Recognizer
|
|
|
|
|
|
- @objc func didTap(_ recognizer: UITapGestureRecognizer) {
|
|
|
+ @objc func tapPdfView(_ recognizer: UITapGestureRecognizer) {
|
|
|
|
|
|
- if navigationController?.isNavigationBarHidden ?? false {
|
|
|
+ pdfThumbnailScrollViewTopAnchor?.isActive = false
|
|
|
|
|
|
- navigationController?.setNavigationBarHidden(false, animated: false)
|
|
|
- pdfThumbnailView.isHidden = false
|
|
|
- pdfView.backgroundColor = NCBrandColor.shared.systemBackground
|
|
|
+ if navigationController?.isNavigationBarHidden ?? false {
|
|
|
+ navigationController?.setNavigationBarHidden(false, animated: true)
|
|
|
+ pdfThumbnailScrollViewTopAnchor = pdfThumbnailScrollView.topAnchor.constraint(equalTo: view.safeAreaLayoutGuide.topAnchor)
|
|
|
|
|
|
} else {
|
|
|
+ navigationController?.setNavigationBarHidden(true, animated: true)
|
|
|
+ pdfThumbnailScrollViewTopAnchor = pdfThumbnailScrollView.topAnchor.constraint(equalTo: view.topAnchor)
|
|
|
+ }
|
|
|
+
|
|
|
+ pdfThumbnailScrollViewTopAnchor?.isActive = true
|
|
|
+
|
|
|
+ handlePageChange()
|
|
|
+ }
|
|
|
|
|
|
- let point = recognizer.location(in: pdfView)
|
|
|
- if point.y > pdfView.frame.height - thumbnailViewHeight { return }
|
|
|
+ @objc func gestureOpenPdfThumbnail(_ recognizer: UIScreenEdgePanGestureRecognizer) {
|
|
|
|
|
|
- navigationController?.setNavigationBarHidden(true, animated: false)
|
|
|
- pdfThumbnailView.isHidden = true
|
|
|
- pdfView.backgroundColor = .black
|
|
|
+ if UIDevice.current.userInterfaceIdiom == .phone && self.pdfThumbnailScrollView.isHidden {
|
|
|
+ if let tipView = self.tipView {
|
|
|
+ tipView.dismiss()
|
|
|
+ NCManageDatabase.shared.addTip(NCGlobal.shared.tipNCViewerPDFThumbnail)
|
|
|
+ self.tipView = nil
|
|
|
+ }
|
|
|
+ self.pdfThumbnailScrollView.isHidden = false
|
|
|
+ self.pdfThumbnailScrollViewWidthAnchor?.constant = thumbnailViewWidth + (UIApplication.shared.keyWindow?.safeAreaInsets.right ?? 0)
|
|
|
+ UIView.animate(withDuration: animateDuration, animations: {
|
|
|
+ self.pdfThumbnailScrollViewTrailingAnchor?.constant = 0
|
|
|
+ self.view.layoutIfNeeded()
|
|
|
+ })
|
|
|
}
|
|
|
+ }
|
|
|
|
|
|
- handlePageChange()
|
|
|
+ @objc func gestureClosePdfThumbnail(_ recognizer: UIScreenEdgePanGestureRecognizer) {
|
|
|
+
|
|
|
+ if recognizer.state == .recognized && UIDevice.current.userInterfaceIdiom == .phone && !self.pdfThumbnailScrollView.isHidden {
|
|
|
+ UIView.animate(withDuration: animateDuration) {
|
|
|
+ self.pdfThumbnailScrollViewTrailingAnchor?.constant = self.thumbnailViewWidth + (UIApplication.shared.keyWindow?.safeAreaInsets.right ?? 0)
|
|
|
+ self.view.layoutIfNeeded()
|
|
|
+ } completion: { _ in
|
|
|
+ self.pdfThumbnailScrollView.isHidden = true
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
// MARK: -
|
|
|
|
|
|
+ func setConstraints() {
|
|
|
+
|
|
|
+ let widthThumbnail = thumbnailViewWidth + (UIApplication.shared.keyWindow?.safeAreaInsets.right ?? 0)
|
|
|
+
|
|
|
+ UIView.animate(withDuration: animateDuration, animations: {
|
|
|
+ if UIDevice.current.userInterfaceIdiom == .phone {
|
|
|
+ // Close
|
|
|
+ self.pdfThumbnailScrollView.isHidden = true
|
|
|
+ self.pdfThumbnailScrollViewTrailingAnchor?.constant = widthThumbnail
|
|
|
+ self.pdfThumbnailScrollViewWidthAnchor?.constant = widthThumbnail
|
|
|
+ } else {
|
|
|
+ // Open
|
|
|
+ self.pdfThumbnailScrollViewTrailingAnchor?.constant = 0
|
|
|
+ self.pdfThumbnailScrollViewWidthAnchor?.constant = widthThumbnail
|
|
|
+ }
|
|
|
+ self.view.layoutIfNeeded()
|
|
|
+ self.pdfView.autoScales = true
|
|
|
+ })
|
|
|
+ }
|
|
|
+
|
|
|
@objc func handlePageChange() {
|
|
|
|
|
|
guard let curPage = pdfView.currentPage?.pageRef?.pageNumber else { pageView.alpha = 0; return }
|
|
|
guard let totalPages = pdfView.document?.pageCount else { return }
|
|
|
|
|
|
+ let visibleRect = CGRect(x: pdfThumbnailScrollView.contentOffset.x, y: pdfThumbnailScrollView.contentOffset.y, width: pdfThumbnailScrollView.bounds.size.width, height: pdfThumbnailScrollView.bounds.size.height)
|
|
|
+ let centerPoint = CGPoint(x: visibleRect.size.width/2, y: visibleRect.size.height/2)
|
|
|
+ let currentPageY = CGFloat(curPage) * thumbnailViewHeight + CGFloat(curPage) * thumbnailPadding
|
|
|
+ var gotoY = currentPageY - centerPoint.y
|
|
|
+
|
|
|
+ let startY = visibleRect.origin.y < 0 ? 0 : (visibleRect.origin.y + thumbnailViewHeight)
|
|
|
+ let endY = visibleRect.origin.y + visibleRect.height
|
|
|
+
|
|
|
+ if currentPageY < startY {
|
|
|
+ if gotoY < 0 { gotoY = 0 }
|
|
|
+ pdfThumbnailScrollView.setContentOffset(CGPoint(x: 0, y: gotoY), animated: true)
|
|
|
+ } else if currentPageY > endY {
|
|
|
+ if gotoY > pdfThumbnailView.frame.height - visibleRect.height {
|
|
|
+ gotoY = pdfThumbnailView.frame.height - visibleRect.height
|
|
|
+ }
|
|
|
+ pdfThumbnailScrollView.setContentOffset(CGPoint(x: 0, y: gotoY), animated: true)
|
|
|
+ } else {
|
|
|
+ print("visible")
|
|
|
+ }
|
|
|
+
|
|
|
pageView.alpha = 1
|
|
|
pageViewLabel.text = String(curPage) + " " + NSLocalizedString("_of_", comment: "") + " " + String(totalPages)
|
|
|
pageViewWidthAnchor?.constant = pageViewLabel.intrinsicContentSize.width + 10
|
|
|
|
|
|
- UIView.animate(withDuration: 1.0, delay: 3.0, animations: {
|
|
|
+ UIView.animate(withDuration: 1.0, delay: 2.5, animations: {
|
|
|
self.pageView.alpha = 0
|
|
|
})
|
|
|
}
|
|
@@ -341,3 +496,12 @@ class NCViewerPDF: UIViewController, NCViewerPDFSearchDelegate {
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+extension NCViewerPDF: EasyTipViewDelegate {
|
|
|
+
|
|
|
+ func easyTipViewDidTap(_ tipView: EasyTipView) {
|
|
|
+ NCManageDatabase.shared.addTip(NCGlobal.shared.tipNCViewerPDFThumbnail)
|
|
|
+ }
|
|
|
+
|
|
|
+ func easyTipViewDidDismiss(_ tipView: EasyTipView) { }
|
|
|
+}
|