marinofaggiana пре 3 година
родитељ
комит
5d63ce8453

+ 10 - 12
iOSClient/Viewer/NCViewerImage/NCViewerImage.storyboard

@@ -79,8 +79,8 @@
                             <scrollView clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="scaleToFill" showsHorizontalScrollIndicator="NO" showsVerticalScrollIndicator="NO" maximumZoomScale="4" translatesAutoresizingMaskIntoConstraints="NO" id="CdQ-LC-Trx">
                                 <rect key="frame" x="0.0" y="0.0" width="414" height="736"/>
                                 <subviews>
-                                    <imageView userInteractionEnabled="NO" contentMode="scaleToFill" horizontalHuggingPriority="251" verticalHuggingPriority="251" image="image" translatesAutoresizingMaskIntoConstraints="NO" id="kPV-JM-UnM">
-                                        <rect key="frame" x="0.0" y="0.0" width="128" height="128"/>
+                                    <imageView userInteractionEnabled="NO" contentMode="scaleAspectFit" horizontalHuggingPriority="251" verticalHuggingPriority="251" image="image" translatesAutoresizingMaskIntoConstraints="NO" id="kPV-JM-UnM">
+                                        <rect key="frame" x="0.0" y="0.0" width="414" height="736"/>
                                     </imageView>
                                     <imageView clipsSubviews="YES" userInteractionEnabled="NO" contentMode="scaleAspectFit" horizontalHuggingPriority="251" verticalHuggingPriority="251" translatesAutoresizingMaskIntoConstraints="NO" id="2AU-85-K8y">
                                         <rect key="frame" x="10" y="10" width="30" height="30"/>
@@ -90,7 +90,7 @@
                                         </constraints>
                                     </imageView>
                                     <label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Label" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="DAi-gz-qGP">
-                                        <rect key="frame" x="48" y="16.666666666666668" width="35.333333333333343" height="17.000000000000004"/>
+                                        <rect key="frame" x="48" y="16.666666666666668" width="346" height="17.000000000000004"/>
                                         <fontDescription key="fontDescription" type="system" pointSize="14"/>
                                         <color key="textColor" white="0.33333333333333331" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
                                         <nil key="highlightedColor"/>
@@ -244,7 +244,7 @@
                                         <rect key="frame" x="25" y="636" width="364" height="100"/>
                                         <subviews>
                                             <button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="8AB-hx-yqN">
-                                                <rect key="frame" x="329" y="65" width="25" height="25"/>
+                                                <rect key="frame" x="328.99999999999994" y="65" width="25" height="25"/>
                                                 <constraints>
                                                     <constraint firstAttribute="width" constant="25" id="6yU-23-dkA"/>
                                                     <constraint firstAttribute="height" constant="25" id="hBk-Ku-BAd"/>
@@ -277,13 +277,13 @@
                                                 <nil key="highlightedColor"/>
                                             </label>
                                             <label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="99:99:99" textAlignment="right" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="OUD-HH-cXH">
-                                                <rect key="frame" x="301" y="42" width="53" height="14.333333333333336"/>
+                                                <rect key="frame" x="300.99999999999994" y="42" width="53" height="14.333333333333336"/>
                                                 <fontDescription key="fontDescription" type="system" pointSize="12"/>
                                                 <nil key="textColor"/>
                                                 <nil key="highlightedColor"/>
                                             </label>
                                             <button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="F9L-PP-AbM">
-                                                <rect key="frame" x="217.00000000000003" y="63.666666666666629" width="20" height="23"/>
+                                                <rect key="frame" x="216.99999999999994" y="63.666666666666629" width="20" height="23"/>
                                                 <constraints>
                                                     <constraint firstAttribute="width" constant="20" id="hlL-XQ-OLa"/>
                                                     <constraint firstAttribute="height" constant="23" id="vEe-Fb-a9N"/>
@@ -340,10 +340,12 @@
                                     <constraint firstItem="DAi-gz-qGP" firstAttribute="centerY" secondItem="2AU-85-K8y" secondAttribute="centerY" id="Lls-5R-JBM"/>
                                     <constraint firstAttribute="trailing" secondItem="DAi-gz-qGP" secondAttribute="trailing" constant="20" id="QWE-Iy-fcM"/>
                                     <constraint firstItem="kPV-JM-UnM" firstAttribute="leading" secondItem="CdQ-LC-Trx" secondAttribute="leading" id="asL-Ft-Lmc"/>
-                                    <constraint firstAttribute="trailing" secondItem="kPV-JM-UnM" secondAttribute="trailing" priority="250" id="fBN-70-6ry"/>
+                                    <constraint firstAttribute="trailing" secondItem="kPV-JM-UnM" secondAttribute="trailing" id="bFX-fz-FdV"/>
                                     <constraint firstItem="DAi-gz-qGP" firstAttribute="leading" secondItem="2AU-85-K8y" secondAttribute="trailing" constant="8" symbolic="YES" id="q8N-jc-KHs"/>
                                     <constraint firstItem="kPV-JM-UnM" firstAttribute="top" secondItem="CdQ-LC-Trx" secondAttribute="top" id="tdo-XY-uqv"/>
-                                    <constraint firstAttribute="bottom" secondItem="kPV-JM-UnM" secondAttribute="bottom" priority="250" id="xTI-ae-JfJ"/>
+                                    <constraint firstItem="kPV-JM-UnM" firstAttribute="height" secondItem="CdQ-LC-Trx" secondAttribute="height" id="u0g-zN-41J"/>
+                                    <constraint firstAttribute="bottom" secondItem="kPV-JM-UnM" secondAttribute="bottom" id="vEd-X2-yGs"/>
+                                    <constraint firstItem="kPV-JM-UnM" firstAttribute="width" secondItem="CdQ-LC-Trx" secondAttribute="width" id="yCC-KH-2fx"/>
                                 </constraints>
                             </scrollView>
                         </subviews>
@@ -368,10 +370,6 @@
                         <outlet property="detailView" destination="P8R-4f-zAl" id="xFW-qq-Cdi"/>
                         <outlet property="detailViewTopConstraint" destination="B4O-kU-vwy" id="8Av-5H-ygG"/>
                         <outlet property="imageView" destination="kPV-JM-UnM" id="TEv-Tc-8pu"/>
-                        <outlet property="imageViewBottomConstraint" destination="xTI-ae-JfJ" id="vdW-Ma-BV1"/>
-                        <outlet property="imageViewLeadingConstraint" destination="asL-Ft-Lmc" id="4cu-ey-QS1"/>
-                        <outlet property="imageViewTopConstraint" destination="tdo-XY-uqv" id="9Ty-3b-gkL"/>
-                        <outlet property="imageViewTrailingConstraint" destination="fBN-70-6ry" id="dZZ-2L-0VJ"/>
                         <outlet property="scrollView" destination="CdQ-LC-Trx" id="3np-FR-s39"/>
                         <outlet property="statusLabel" destination="DAi-gz-qGP" id="zZH-1B-HiI"/>
                         <outlet property="statusViewImage" destination="2AU-85-K8y" id="22h-Ec-bj0"/>

+ 1 - 1
iOSClient/Viewer/NCViewerImage/NCViewerImage.swift

@@ -518,7 +518,7 @@ extension NCViewerImage: UIGestureRecognizerDelegate {
         if currentViewerImageZoom?.detailView.isShow() ?? false {
             
             UIView.animate(withDuration: 0.2) {
-                self.currentViewerImageZoom?.updateConstraints()
+//                self.currentViewerImageZoom?.updateConstraints()
                 // VideoToolBar
                 if self.currentMetadata.classFile == NCCommunicationCommon.typeClassFile.audio.rawValue || self.currentMetadata.classFile == NCCommunicationCommon.typeClassFile.video.rawValue {
                     self.viewerVideo?.viewerVideoToolBar?.showToolBar()

+ 50 - 34
iOSClient/Viewer/NCViewerImage/NCViewerImageZoom.swift

@@ -33,11 +33,6 @@ protocol NCViewerImageZoomDelegate {
 
 class NCViewerImageZoom: UIViewController {
     
-    @IBOutlet weak var imageViewBottomConstraint: NSLayoutConstraint!
-    @IBOutlet weak var imageViewLeadingConstraint: NSLayoutConstraint!
-    @IBOutlet weak var imageViewTopConstraint: NSLayoutConstraint!
-    @IBOutlet weak var imageViewTrailingConstraint: NSLayoutConstraint!
-        
     @IBOutlet weak var detailViewTopConstraint: NSLayoutConstraint!
     
     @IBOutlet weak var scrollView: UIScrollView!
@@ -75,7 +70,8 @@ class NCViewerImageZoom: UIViewController {
         super.viewDidLoad()
         
         scrollView.delegate = self
-        scrollView.contentInsetAdjustmentBehavior = .never
+        scrollView.maximumZoomScale = 4
+        scrollView.minimumZoomScale = 1
         
         view.addGestureRecognizer(doubleTapGestureRecognizer)
         
@@ -100,8 +96,8 @@ class NCViewerImageZoom: UIViewController {
             statusLabel.text = ""
         }
         
-        updateZoom()
-        updateConstraints()
+//        updateZoom()
+//        updateConstraints()
     }
     
     override func viewWillAppear(_ animated: Bool) {
@@ -109,8 +105,8 @@ class NCViewerImageZoom: UIViewController {
         
         if !detailView.isShow() {
             
-            updateZoom()
-            updateConstraints()
+//            updateZoom()
+//            updateConstraints()
         }
         
         delegate?.willAppearImageZoom(viewerImageZoom: self, metadata: metadata)
@@ -130,8 +126,8 @@ class NCViewerImageZoom: UIViewController {
             detailViewTopConstraint.constant = 0
             detailView.hide()
             
-            updateZoom()
-            updateConstraints()
+//            updateZoom()
+//            updateConstraints()
         }
         
         delegate?.didAppearImageZoom(viewerImageZoom: self, metadata: metadata)
@@ -143,16 +139,16 @@ class NCViewerImageZoom: UIViewController {
         if detailView.isShow() {
             
             detailView.hide()
-            updateZoom()
-            updateConstraints()
+//            updateZoom()
+//            updateConstraints()
         }
     }
     
     override func viewDidLayoutSubviews() {
         super.viewDidLayoutSubviews()
         
-        updateZoom()
-        updateConstraints()
+//        updateZoom()
+//        updateConstraints()
     }
     
     //MARK: - Gesture
@@ -195,8 +191,8 @@ class NCViewerImageZoom: UIViewController {
             topPoint = CGPoint(x: currentLocation.x, y: currentLocation.y)
             
             // save start
-            startImageViewTopConstraint = imageViewTopConstraint.constant
-            startImageViewBottomConstraint = imageViewBottomConstraint.constant
+//            startImageViewTopConstraint = imageViewTopConstraint.constant
+//            startImageViewBottomConstraint = imageViewBottomConstraint.constant
              
             // VideoToolBar
             self.videoToolBar.hideToolBar()
@@ -205,15 +201,15 @@ class NCViewerImageZoom: UIViewController {
             
             if !detailView.isShow() {
                 UIView.animate(withDuration: 0.3) {
-                    self.updateConstraints()
+//                    self.updateConstraints()
                 } completion: { (_) in
-                    self.updateZoom()
-                    self.updateConstraints()
+//                    self.updateZoom()
+//                    self.updateConstraints()
                 }
             } else if detailView.isSavedContraint() {
                 UIView.animate(withDuration: 0.3) {
-                    self.imageViewTopConstraint.constant = self.detailView.imageViewTopConstraintConstant
-                    self.imageViewBottomConstraint.constant = self.detailView.imageViewBottomConstraintConstant
+//                    self.imageViewTopConstraint.constant = self.detailView.imageViewTopConstraintConstant
+//                    self.imageViewBottomConstraint.constant = self.detailView.imageViewBottomConstraintConstant
                     self.detailViewTopConstraint.constant = self.detailView.detailViewTopConstraintConstant
                     self.view.layoutIfNeeded()
                 } completion: { (_) in
@@ -236,9 +232,9 @@ class NCViewerImageZoom: UIViewController {
             if currentLocation.y < topPoint.y { topPoint = currentLocation }
             let deltaY = startPoint.y - currentLocation.y
             
-            imageViewTopConstraint.constant = startImageViewTopConstraint + currentLocation.y
-            imageViewBottomConstraint.constant = startImageViewBottomConstraint - currentLocation.y
-            detailViewTopConstraint.constant = -imageViewBottomConstraint.constant
+//            imageViewTopConstraint.constant = startImageViewTopConstraint + currentLocation.y
+//            imageViewBottomConstraint.constant = startImageViewBottomConstraint - currentLocation.y
+//            detailViewTopConstraint.constant = -imageViewBottomConstraint.constant
             
             // DISMISS
             if imageView.center.y > view.center.y + 100 {
@@ -255,15 +251,15 @@ class NCViewerImageZoom: UIViewController {
                     gestureRecognizer.state = .ended
                      
                     UIView.animate(withDuration: 0.3) {
-                        self.imageViewTopConstraint.constant = self.startImageViewTopConstraint - self.detailView.frame.height
-                        self.imageViewBottomConstraint.constant = self.startImageViewBottomConstraint + self.detailView.frame.height
-                        self.detailViewTopConstraint.constant = -self.imageViewBottomConstraint.constant
+//                        self.imageViewTopConstraint.constant = self.startImageViewTopConstraint - self.detailView.frame.height
+//                        self.imageViewBottomConstraint.constant = self.startImageViewBottomConstraint + self.detailView.frame.height
+//                        self.detailViewTopConstraint.constant = -self.imageViewBottomConstraint.constant
                         self.view.layoutIfNeeded()
                     } completion: { (_) in
                         // Save detail constraints
-                        self.detailView.imageViewTopConstraintConstant = self.imageViewTopConstraint.constant
-                        self.detailView.imageViewBottomConstraintConstant = self.imageViewBottomConstraint.constant
-                        self.detailView.detailViewTopConstraintConstant = self.detailViewTopConstraint.constant
+//                        self.detailView.imageViewTopConstraintConstant = self.imageViewTopConstraint.constant
+//                        self.detailView.imageViewBottomConstraintConstant = self.imageViewBottomConstraint.constant
+//                        self.detailView.detailViewTopConstraintConstant = self.detailViewTopConstraint.constant
                     }
                 }
                 
@@ -286,6 +282,7 @@ class NCViewerImageZoom: UIViewController {
     
     //MARK: - Function
 
+    /*
     private func updateZoom() {
         
         let widthScale = self.view.bounds.size.width / imageView.bounds.width
@@ -319,6 +316,7 @@ class NCViewerImageZoom: UIViewController {
 
         print("x: \(xOffset) - y: \(yOffset) - contentWidth: \(contentWidth) - contentHeight: \(contentHeight)")
     }
+    */
 }
 
 extension NCViewerImageZoom: UIScrollViewDelegate {
@@ -328,8 +326,26 @@ extension NCViewerImageZoom: UIScrollViewDelegate {
     }
     
     func scrollViewDidZoom(_ scrollView: UIScrollView) {
-        updateConstraints()
-    }
+        if scrollView.zoomScale > 1 {
+            if let image = imageView.image {
+                let ratioW = imageView.frame.width / image.size.width
+                let ratioH = imageView.frame.height / image.size.height
+                
+                let ratio = ratioW < ratioH ? ratioW : ratioH
+                let newWidth = image.size.width * ratio
+                let newHeight = image.size.height * ratio
+                let conditionLeft = newWidth*scrollView.zoomScale > imageView.frame.width
+                let left = 0.5 * (conditionLeft ? newWidth - imageView.frame.width : (scrollView.frame.width - scrollView.contentSize.width))
+                let conditioTop = newHeight*scrollView.zoomScale > imageView.frame.height
+                
+                let top = 0.5 * (conditioTop ? newHeight - imageView.frame.height : (scrollView.frame.height - scrollView.contentSize.height))
+                
+                scrollView.contentInset = UIEdgeInsets(top: top, left: left, bottom: top, right: left)
+                
+            }
+        } else {
+            scrollView.contentInset = .zero
+        }    }
     
     func scrollViewDidScroll(_ scrollView: UIScrollView) {
         self.delegate?.photoPageViewController(self, scrollViewDidScroll: scrollView)