|
@@ -45,6 +45,7 @@ class NCViewerPDF: UIViewController, NCViewerPDFSearchDelegate {
|
|
|
private let thumbnailViewWidth: CGFloat = 80
|
|
|
private let thumbnailPadding: CGFloat = 2
|
|
|
private let animateDuration: TimeInterval = 0.3
|
|
|
+ private let pageViewtopAnchor: CGFloat = UIDevice.current.userInterfaceIdiom == .phone ? 10 : 30
|
|
|
|
|
|
private var defaultBackgroundColor: UIColor = .clear
|
|
|
|
|
@@ -72,11 +73,7 @@ class NCViewerPDF: UIViewController, NCViewerPDFSearchDelegate {
|
|
|
|
|
|
// 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 = PDFView(frame: CGRect(x: 0, y: 0, width: view.frame.width, height: view.frame.height))
|
|
|
pdfView.autoresizingMask = [.flexibleWidth, .flexibleHeight, .flexibleTopMargin, .flexibleLeftMargin]
|
|
|
pdfView.document = pdfDocument
|
|
|
pdfView.autoScales = true
|
|
@@ -107,11 +104,8 @@ class NCViewerPDF: UIViewController, NCViewerPDFSearchDelegate {
|
|
|
pdfThumbnailView.layoutMode = .vertical
|
|
|
pdfThumbnailView.thumbnailSize = CGSize(width: thumbnailViewHeight, height: thumbnailViewHeight)
|
|
|
pdfThumbnailView.backgroundColor = .clear
|
|
|
- if UIDevice.current.userInterfaceIdiom == .phone {
|
|
|
- self.pdfThumbnailScrollView.isHidden = true
|
|
|
- } else {
|
|
|
- self.pdfThumbnailScrollView.isHidden = false
|
|
|
- }
|
|
|
+
|
|
|
+ pdfThumbnailScrollView.isHidden = true
|
|
|
pdfThumbnailScrollView.addSubview(pdfThumbnailView)
|
|
|
|
|
|
NSLayoutConstraint.activate([
|
|
@@ -140,7 +134,7 @@ class NCViewerPDF: UIViewController, NCViewerPDFSearchDelegate {
|
|
|
view.addSubview(pageView)
|
|
|
|
|
|
NSLayoutConstraint.activate([
|
|
|
- pageView.topAnchor.constraint(equalTo: view.safeAreaLayoutGuide.topAnchor, constant: 10),
|
|
|
+ pageView.topAnchor.constraint(equalTo: view.safeAreaLayoutGuide.topAnchor, constant: pageViewtopAnchor),
|
|
|
pageView.heightAnchor.constraint(equalToConstant: 30),
|
|
|
pageView.leftAnchor.constraint(equalTo: view.safeAreaLayoutGuide.leftAnchor, constant: 10)
|
|
|
])
|
|
@@ -198,25 +192,22 @@ class NCViewerPDF: UIViewController, NCViewerPDFSearchDelegate {
|
|
|
NotificationCenter.default.addObserver(self, selector: #selector(handlePageChange), name: Notification.Name.PDFViewPageChanged, object: nil)
|
|
|
|
|
|
// Tip
|
|
|
- if UIDevice.current.userInterfaceIdiom == .phone && !NCManageDatabase.shared.tipExists(NCGlobal.shared.tipNCViewerPDFThumbnail){
|
|
|
-
|
|
|
- var preferences = EasyTipView.Preferences()
|
|
|
- preferences.drawing.foregroundColor = .white
|
|
|
- preferences.drawing.backgroundColor = NCBrandColor.shared.nextcloud
|
|
|
- preferences.drawing.textAlignment = .left
|
|
|
- preferences.drawing.arrowPosition = .right
|
|
|
- preferences.drawing.cornerRadius = 10
|
|
|
+ var preferences = EasyTipView.Preferences()
|
|
|
+ preferences.drawing.foregroundColor = .white
|
|
|
+ preferences.drawing.backgroundColor = NCBrandColor.shared.nextcloud
|
|
|
+ preferences.drawing.textAlignment = .left
|
|
|
+ preferences.drawing.arrowPosition = .right
|
|
|
+ preferences.drawing.cornerRadius = 10
|
|
|
|
|
|
- preferences.positioning.bubbleInsets.right = UIApplication.shared.keyWindow?.safeAreaInsets.right ?? 0
|
|
|
+ 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
|
|
|
+ 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)
|
|
|
- }
|
|
|
+ tipView = EasyTipView(text: NSLocalizedString("_tip_pdf_thumbnails_", comment: ""), preferences: preferences, delegate: self)
|
|
|
|
|
|
setConstraints()
|
|
|
handlePageChange()
|
|
@@ -225,7 +216,7 @@ class NCViewerPDF: UIViewController, NCViewerPDFSearchDelegate {
|
|
|
override func viewDidAppear(_ animated: Bool) {
|
|
|
super.viewDidAppear(animated)
|
|
|
|
|
|
- self.tipView?.show(forView: self.pdfThumbnailScrollView, withinSuperview: self.view)
|
|
|
+ showTip()
|
|
|
}
|
|
|
|
|
|
@objc func viewUnload() {
|
|
@@ -236,15 +227,13 @@ class NCViewerPDF: UIViewController, NCViewerPDFSearchDelegate {
|
|
|
override func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator) {
|
|
|
super.viewWillTransition(to: size, with: coordinator)
|
|
|
|
|
|
+ tipView?.dismiss()
|
|
|
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
|
|
|
- }
|
|
|
+ self.pdfThumbnailScrollViewTrailingAnchor?.constant = self.thumbnailViewWidth + (UIApplication.shared.keyWindow?.safeAreaInsets.right ?? 0)
|
|
|
+ self.pdfThumbnailScrollView.isHidden = true
|
|
|
}, completion: { context in
|
|
|
self.setConstraints()
|
|
|
+ self.showTip()
|
|
|
})
|
|
|
}
|
|
|
|
|
@@ -263,6 +252,15 @@ class NCViewerPDF: UIViewController, NCViewerPDFSearchDelegate {
|
|
|
NotificationCenter.default.removeObserver(self, name: Notification.Name.PDFViewPageChanged, object: nil)
|
|
|
}
|
|
|
|
|
|
+ // MARK: - Tip
|
|
|
+
|
|
|
+ func showTip() {
|
|
|
+
|
|
|
+ if !NCManageDatabase.shared.tipExists(NCGlobal.shared.tipNCViewerPDFThumbnail) {
|
|
|
+ self.tipView?.show(forView: self.pdfThumbnailScrollView, withinSuperview: self.view)
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
// MARK: - NotificationCenter
|
|
|
|
|
|
@objc func uploadStartFile(_ notification: NSNotification) {
|
|
@@ -406,24 +404,22 @@ class NCViewerPDF: UIViewController, NCViewerPDFSearchDelegate {
|
|
|
@objc func gestureOpenPdfThumbnail(_ recognizer: UIScreenEdgePanGestureRecognizer) {
|
|
|
guard let pdfDocument = pdfView.document, !pdfDocument.isLocked else { return }
|
|
|
|
|
|
- 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()
|
|
|
- })
|
|
|
+ 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()
|
|
|
+ })
|
|
|
}
|
|
|
|
|
|
@objc func gestureClosePdfThumbnail(_ recognizer: UIScreenEdgePanGestureRecognizer) {
|
|
|
|
|
|
- if recognizer.state == .recognized && UIDevice.current.userInterfaceIdiom == .phone && !self.pdfThumbnailScrollView.isHidden {
|
|
|
+ if recognizer.state == .recognized && !self.pdfThumbnailScrollView.isHidden {
|
|
|
UIView.animate(withDuration: animateDuration) {
|
|
|
self.pdfThumbnailScrollViewTrailingAnchor?.constant = self.thumbnailViewWidth + (UIApplication.shared.keyWindow?.safeAreaInsets.right ?? 0)
|
|
|
self.view.layoutIfNeeded()
|
|
@@ -440,16 +436,11 @@ class NCViewerPDF: UIViewController, NCViewerPDFSearchDelegate {
|
|
|
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
|
|
|
- }
|
|
|
+ // Close
|
|
|
+ self.pdfThumbnailScrollView.isHidden = true
|
|
|
+ self.pdfThumbnailScrollViewTrailingAnchor?.constant = widthThumbnail
|
|
|
+ self.pdfThumbnailScrollViewWidthAnchor?.constant = widthThumbnail
|
|
|
+
|
|
|
self.view.layoutIfNeeded()
|
|
|
self.pdfView.autoScales = true
|
|
|
})
|