|
@@ -28,6 +28,8 @@ import NextcloudKit
|
|
|
|
|
|
class NCViewerPDF: UIViewController, NCViewerPDFSearchDelegate {
|
|
|
|
|
|
+ @IBOutlet weak var pdfContainer: UIView!
|
|
|
+
|
|
|
var metadata = tableMetadata()
|
|
|
var imageIcon: UIImage?
|
|
|
|
|
@@ -75,12 +77,13 @@ class NCViewerPDF: UIViewController, NCViewerPDFSearchDelegate {
|
|
|
defaultBackgroundColor = pdfView.backgroundColor
|
|
|
view.backgroundColor = defaultBackgroundColor
|
|
|
|
|
|
+ navigationController?.navigationBar.prefersLargeTitles = true
|
|
|
navigationItem.rightBarButtonItem = UIBarButtonItem(image: UIImage(named: "more")!.image(color: .label, size: 25), style: .plain, target: self, action: #selector(self.openMenuMore))
|
|
|
navigationItem.title = metadata.fileNameView
|
|
|
|
|
|
// PDF VIEW
|
|
|
|
|
|
- pdfView = PDFView(frame: CGRect(x: 0, y: 0, width: view.frame.width, height: view.frame.height))
|
|
|
+ pdfView = PDFView(frame: CGRect(x: 0, y: 0, width: pdfContainer.frame.width, height: pdfContainer.frame.height))
|
|
|
pdfView.autoresizingMask = [.flexibleWidth, .flexibleHeight, .flexibleTopMargin, .flexibleLeftMargin]
|
|
|
pdfView.document = pdfDocument
|
|
|
pdfView.document?.page(at: 0)?.annotations.forEach({
|
|
@@ -89,22 +92,19 @@ class NCViewerPDF: UIViewController, NCViewerPDFSearchDelegate {
|
|
|
pdfView.autoScales = true
|
|
|
pdfView.displayMode = .singlePageContinuous
|
|
|
pdfView.displayDirection = .vertical
|
|
|
- // pdfView.maxScaleFactor = 4.0
|
|
|
- // pdfView.minScaleFactor = pdfView.scaleFactorForSizeToFit
|
|
|
- // pdfView.usePageViewController(true)
|
|
|
- view.addSubview(pdfView)
|
|
|
+ pdfContainer.addSubview(pdfView)
|
|
|
|
|
|
// PDF THUMBNAIL
|
|
|
|
|
|
pdfThumbnailScrollView.translatesAutoresizingMaskIntoConstraints = false
|
|
|
pdfThumbnailScrollView.backgroundColor = defaultBackgroundColor
|
|
|
pdfThumbnailScrollView.showsVerticalScrollIndicator = false
|
|
|
- view.addSubview(pdfThumbnailScrollView)
|
|
|
+ pdfContainer.addSubview(pdfThumbnailScrollView)
|
|
|
|
|
|
- pdfThumbnailScrollView.bottomAnchor.constraint(equalTo: view.bottomAnchor).isActive = true
|
|
|
- pdfThumbnailScrollViewTopAnchor = pdfThumbnailScrollView.topAnchor.constraint(equalTo: view.safeAreaLayoutGuide.topAnchor)
|
|
|
+ pdfThumbnailScrollView.bottomAnchor.constraint(equalTo: pdfContainer.bottomAnchor).isActive = true
|
|
|
+ pdfThumbnailScrollViewTopAnchor = pdfThumbnailScrollView.topAnchor.constraint(equalTo: pdfContainer.safeAreaLayoutGuide.topAnchor)
|
|
|
pdfThumbnailScrollViewTopAnchor?.isActive = true
|
|
|
- pdfThumbnailScrollViewTrailingAnchor = pdfThumbnailScrollView.trailingAnchor.constraint(equalTo: view.trailingAnchor)
|
|
|
+ pdfThumbnailScrollViewTrailingAnchor = pdfThumbnailScrollView.trailingAnchor.constraint(equalTo: pdfContainer.trailingAnchor)
|
|
|
pdfThumbnailScrollViewTrailingAnchor?.isActive = true
|
|
|
pdfThumbnailScrollViewWidthAnchor = pdfThumbnailScrollView.widthAnchor.constraint(equalToConstant: thumbnailViewWidth)
|
|
|
pdfThumbnailScrollViewWidthAnchor?.isActive = true
|
|
@@ -141,12 +141,12 @@ class NCViewerPDF: UIViewController, NCViewerPDFSearchDelegate {
|
|
|
pageView.backgroundColor = .systemBackground.withAlphaComponent(
|
|
|
UIAccessibility.isReduceTransparencyEnabled ? 1 : 0.5
|
|
|
)
|
|
|
- view.addSubview(pageView)
|
|
|
+ pdfContainer.addSubview(pageView)
|
|
|
|
|
|
NSLayoutConstraint.activate([
|
|
|
- pageView.topAnchor.constraint(equalTo: view.safeAreaLayoutGuide.topAnchor, constant: pageViewtopAnchor),
|
|
|
+ pageView.topAnchor.constraint(equalTo: pdfContainer.safeAreaLayoutGuide.topAnchor, constant: pageViewtopAnchor),
|
|
|
pageView.heightAnchor.constraint(equalToConstant: 30),
|
|
|
- pageView.leftAnchor.constraint(equalTo: view.safeAreaLayoutGuide.leftAnchor, constant: 10)
|
|
|
+ pageView.leftAnchor.constraint(equalTo: pdfContainer.safeAreaLayoutGuide.leftAnchor, constant: 10)
|
|
|
])
|
|
|
pageViewWidthAnchor = pageView.widthAnchor.constraint(equalToConstant: 10)
|
|
|
pageViewWidthAnchor?.isActive = true
|
|
@@ -188,37 +188,6 @@ class NCViewerPDF: UIViewController, NCViewerPDFSearchDelegate {
|
|
|
swipePdfThumbnailScrollView.direction = .right
|
|
|
pdfThumbnailScrollView.addGestureRecognizer(swipePdfThumbnailScrollView)
|
|
|
|
|
|
- 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)
|
|
|
- NotificationCenter.default.addObserver(self, selector: #selector(moveFile(_:)), name: NSNotification.Name(rawValue: NCGlobal.shared.notificationCenterMoveFile), object: nil)
|
|
|
- NotificationCenter.default.addObserver(self, selector: #selector(uploadStartFile(_:)), name: NSNotification.Name(rawValue: NCGlobal.shared.notificationCenterUploadStartFile), object: nil)
|
|
|
- NotificationCenter.default.addObserver(self, selector: #selector(uploadedFile(_:)), name: NSNotification.Name(rawValue: NCGlobal.shared.notificationCenterUploadedFile), object: nil)
|
|
|
-
|
|
|
- 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(goToPage), name: NSNotification.Name(rawValue: NCGlobal.shared.notificationCenterMenuGotToPageInPDF), object: nil)
|
|
|
-
|
|
|
- NotificationCenter.default.addObserver(self, selector: #selector(handlePageChange), name: Notification.Name.PDFViewPageChanged, object: nil)
|
|
|
-
|
|
|
- // Tip
|
|
|
- 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 = window?.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()
|
|
|
}
|
|
@@ -226,6 +195,12 @@ class NCViewerPDF: UIViewController, NCViewerPDFSearchDelegate {
|
|
|
override func viewDidAppear(_ animated: Bool) {
|
|
|
super.viewDidAppear(animated)
|
|
|
|
|
|
+ UIView.animate(withDuration: 0.1, animations: {
|
|
|
+ if let pdf = self.pdfView.document, let page = pdf.page(at: 0) {
|
|
|
+ self.pdfView.go(to: page)
|
|
|
+ }
|
|
|
+ })
|
|
|
+
|
|
|
showTip()
|
|
|
}
|
|
|
|
|
@@ -406,12 +381,12 @@ class NCViewerPDF: UIViewController, NCViewerPDFSearchDelegate {
|
|
|
if navigationController?.isNavigationBarHidden ?? false {
|
|
|
navigationController?.setNavigationBarHidden(false, animated: true)
|
|
|
hideStatusBar = false
|
|
|
- pdfThumbnailScrollViewTopAnchor = pdfThumbnailScrollView.topAnchor.constraint(equalTo: view.safeAreaLayoutGuide.topAnchor)
|
|
|
+ pdfThumbnailScrollViewTopAnchor = pdfThumbnailScrollView.topAnchor.constraint(equalTo: pdfContainer.safeAreaLayoutGuide.topAnchor)
|
|
|
|
|
|
} else {
|
|
|
navigationController?.setNavigationBarHidden(true, animated: true)
|
|
|
hideStatusBar = true
|
|
|
- pdfThumbnailScrollViewTopAnchor = pdfThumbnailScrollView.topAnchor.constraint(equalTo: view.topAnchor)
|
|
|
+ pdfThumbnailScrollViewTopAnchor = pdfThumbnailScrollView.topAnchor.constraint(equalTo: pdfContainer.topAnchor)
|
|
|
}
|
|
|
|
|
|
pdfThumbnailScrollViewTopAnchor?.isActive = true
|
|
@@ -448,7 +423,8 @@ class NCViewerPDF: UIViewController, NCViewerPDFSearchDelegate {
|
|
|
self.pdfThumbnailScrollViewWidthAnchor?.constant = thumbnailViewWidth + (window?.safeAreaInsets.right ?? 0)
|
|
|
UIView.animate(withDuration: animateDuration, animations: {
|
|
|
self.pdfThumbnailScrollViewTrailingAnchor?.constant = 0
|
|
|
- self.view.layoutIfNeeded()
|
|
|
+ // self.view.layoutIfNeeded()
|
|
|
+ self.pdfContainer.layoutIfNeeded()
|
|
|
})
|
|
|
}
|
|
|
|
|
@@ -457,7 +433,8 @@ class NCViewerPDF: UIViewController, NCViewerPDFSearchDelegate {
|
|
|
|
|
|
UIView.animate(withDuration: animateDuration) {
|
|
|
self.pdfThumbnailScrollViewTrailingAnchor?.constant = self.thumbnailViewWidth + (self.window?.safeAreaInsets.right ?? 0)
|
|
|
- self.view.layoutIfNeeded()
|
|
|
+ // self.view.layoutIfNeeded()
|
|
|
+ self.pdfContainer.layoutIfNeeded()
|
|
|
} completion: { _ in
|
|
|
self.pdfThumbnailScrollView.isHidden = true
|
|
|
}
|
|
@@ -475,7 +452,8 @@ class NCViewerPDF: UIViewController, NCViewerPDFSearchDelegate {
|
|
|
self.pdfThumbnailScrollViewTrailingAnchor?.constant = widthThumbnail
|
|
|
self.pdfThumbnailScrollViewWidthAnchor?.constant = widthThumbnail
|
|
|
|
|
|
- self.view.layoutIfNeeded()
|
|
|
+ // self.view.layoutIfNeeded()
|
|
|
+ self.pdfContainer.layoutIfNeeded()
|
|
|
self.pdfView.autoScales = true
|
|
|
})
|
|
|
}
|