marinofaggiana 3 years ago
parent
commit
f8f5b1fa08

+ 13 - 13
iOSClient/Viewer/NCViewerImage/NCViewerImage.storyboard

@@ -96,17 +96,17 @@
                                         <nil key="highlightedColor"/>
                                     </label>
                                     <view hidden="YES" contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="P8R-4f-zAl" customClass="NCViewerImageDetailView" customModule="Nextcloud" customModuleProvider="target">
-                                        <rect key="frame" x="0.0" y="736" width="414" height="375"/>
+                                        <rect key="frame" x="0.0" y="736" width="414" height="345"/>
                                         <subviews>
                                             <view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="HRq-3M-yeb">
-                                                <rect key="frame" x="15" y="50" width="384" height="1"/>
+                                                <rect key="frame" x="15" y="20" width="384" height="1"/>
                                                 <color key="backgroundColor" white="0.66666666666666663" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
                                                 <constraints>
                                                     <constraint firstAttribute="height" constant="1" id="X4S-cr-F2P"/>
                                                 </constraints>
                                             </view>
                                             <label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="size" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="WXS-Lw-DkI">
-                                                <rect key="frame" x="15" y="66" width="80" height="16"/>
+                                                <rect key="frame" x="15" y="36" width="80" height="16"/>
                                                 <constraints>
                                                     <constraint firstAttribute="width" constant="80" id="DLa-7b-rDS"/>
                                                 </constraints>
@@ -115,13 +115,13 @@
                                                 <nil key="highlightedColor"/>
                                             </label>
                                             <label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="size value" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="XLb-0a-du9">
-                                                <rect key="frame" x="105" y="66" width="294" height="16"/>
+                                                <rect key="frame" x="105" y="36" width="294" height="16"/>
                                                 <fontDescription key="fontDescription" type="system" pointSize="13"/>
                                                 <color key="textColor" white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
                                                 <nil key="highlightedColor"/>
                                             </label>
                                             <label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="date" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="Son-CZ-zFa">
-                                                <rect key="frame" x="15" y="92" width="80" height="16"/>
+                                                <rect key="frame" x="15" y="62" width="80" height="16"/>
                                                 <constraints>
                                                     <constraint firstAttribute="width" constant="80" id="e83-SZ-3FA"/>
                                                 </constraints>
@@ -130,13 +130,13 @@
                                                 <nil key="highlightedColor"/>
                                             </label>
                                             <label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="date value" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="hBd-KD-Jq5">
-                                                <rect key="frame" x="105" y="92" width="294" height="16"/>
+                                                <rect key="frame" x="105" y="62" width="294" height="16"/>
                                                 <fontDescription key="fontDescription" type="system" pointSize="13"/>
                                                 <color key="textColor" white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
                                                 <nil key="highlightedColor"/>
                                             </label>
                                             <label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="dim" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="uaE-Lv-t0Q">
-                                                <rect key="frame" x="15" y="118" width="80" height="16"/>
+                                                <rect key="frame" x="15" y="88" width="80" height="16"/>
                                                 <constraints>
                                                     <constraint firstAttribute="width" constant="80" id="iwq-Fq-8U0"/>
                                                 </constraints>
@@ -145,19 +145,19 @@
                                                 <nil key="highlightedColor"/>
                                             </label>
                                             <label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="dim value" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="n1C-OB-gq2">
-                                                <rect key="frame" x="105" y="118" width="294" height="16"/>
+                                                <rect key="frame" x="105" y="88" width="294" height="16"/>
                                                 <fontDescription key="fontDescription" type="system" pointSize="13"/>
                                                 <color key="textColor" white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
                                                 <nil key="highlightedColor"/>
                                             </label>
                                             <mapView clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="scaleToFill" mapType="standard" translatesAutoresizingMaskIntoConstraints="NO" id="Typ-A8-XIO">
-                                                <rect key="frame" x="15" y="173" width="384" height="174"/>
+                                                <rect key="frame" x="15" y="143" width="384" height="174"/>
                                                 <constraints>
                                                     <constraint firstAttribute="height" constant="174" id="VRv-eR-bwo"/>
                                                 </constraints>
                                             </mapView>
                                             <button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="left" contentVerticalAlignment="center" buttonType="system" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="oov-9f-Oeu">
-                                                <rect key="frame" x="15" y="347" width="384" height="28"/>
+                                                <rect key="frame" x="15" y="317" width="384" height="28"/>
                                                 <fontDescription key="fontDescription" type="system" pointSize="13"/>
                                                 <state key="normal" title="location"/>
                                                 <connections>
@@ -165,7 +165,7 @@
                                                 </connections>
                                             </button>
                                             <label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="lens" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="uYI-ic-d8g">
-                                                <rect key="frame" x="15" y="142" width="80" height="16"/>
+                                                <rect key="frame" x="15" y="112" width="80" height="16"/>
                                                 <constraints>
                                                     <constraint firstAttribute="width" constant="80" id="egy-z4-Im6"/>
                                                 </constraints>
@@ -174,7 +174,7 @@
                                                 <nil key="highlightedColor"/>
                                             </label>
                                             <label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="lens value" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="ix8-uQ-chU">
-                                                <rect key="frame" x="105" y="142" width="294" height="16"/>
+                                                <rect key="frame" x="105" y="112" width="294" height="16"/>
                                                 <fontDescription key="fontDescription" type="system" pointSize="13"/>
                                                 <color key="textColor" white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
                                                 <nil key="highlightedColor"/>
@@ -194,7 +194,7 @@
                                             <constraint firstItem="ix8-uQ-chU" firstAttribute="centerY" secondItem="uYI-ic-d8g" secondAttribute="centerY" id="Oae-3R-C5Z"/>
                                             <constraint firstAttribute="trailing" secondItem="ix8-uQ-chU" secondAttribute="trailing" constant="15" id="TIp-le-wVn"/>
                                             <constraint firstItem="hBd-KD-Jq5" firstAttribute="centerY" secondItem="Son-CZ-zFa" secondAttribute="centerY" id="Tez-na-gqC"/>
-                                            <constraint firstItem="HRq-3M-yeb" firstAttribute="top" secondItem="P8R-4f-zAl" secondAttribute="top" constant="50" id="UF1-fO-9hX"/>
+                                            <constraint firstItem="HRq-3M-yeb" firstAttribute="top" secondItem="P8R-4f-zAl" secondAttribute="top" constant="20" id="UF1-fO-9hX"/>
                                             <constraint firstAttribute="bottom" secondItem="oov-9f-Oeu" secondAttribute="bottom" id="YuK-2v-kzk"/>
                                             <constraint firstItem="hBd-KD-Jq5" firstAttribute="leading" secondItem="Son-CZ-zFa" secondAttribute="trailing" constant="10" id="YuO-13-KTh"/>
                                             <constraint firstItem="WXS-Lw-DkI" firstAttribute="leading" secondItem="P8R-4f-zAl" secondAttribute="leading" constant="15" id="bRd-bi-Imh"/>

+ 31 - 12
iOSClient/Viewer/NCViewerImage/NCViewerImageZoom.swift

@@ -151,6 +151,19 @@ class NCViewerImageZoom: UIViewController {
     @objc func didPanWith(gestureRecognizer: UIPanGestureRecognizer) {
                 
         let currentLocation = gestureRecognizer.translation(in: self.view)
+        let imageViewCentetY = imageView.center.y
+        let viewCenterY = view.center.y
+        var constraintHeight: CGFloat = 0
+        
+        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 imageHeight = image.size.height * ratio
+            constraintHeight = self.detailView.frame.height - ((self.view.frame.height - imageHeight) / 2)
+        }
+        
+        print("currentLocation: \(currentLocation), imageViewCentetY: \(imageViewCentetY), viewCenterY: \(viewCenterY)")
         
         switch gestureRecognizer.state {
         case .began:
@@ -184,34 +197,40 @@ class NCViewerImageZoom: UIViewController {
             detailViewConstraint.constant = currentLocation.y
             
             // DISMISS
-            if imageView.center.y > view.center.y + 10 {
+            if detailView.isHidden && (imageViewCentetY > viewCenterY + 10) {
                 
                 delegate?.dismissImageZoom()
             }
 
             // OPEN DETAIL
-            if (imageView.center.y < view.center.y - 20) && detailView.isHidden {
-                         
+            if detailView.isHidden && (imageViewCentetY < viewCenterY - 20) {
+                       
                 self.detailView.show(textColor: self.viewerImage?.textColor)
                 gestureRecognizer.state = .ended
                 
                 UIView.animate(withDuration: 0.3) {
-                    self.imageViewTopConstraint.constant = -self.detailView.frame.height
-                    self.imageViewBottomConstraint.constant = self.detailView.frame.height
-                    self.detailViewConstraint.constant = 200
+                    self.imageViewTopConstraint.constant = -constraintHeight
+                    self.imageViewBottomConstraint.constant = constraintHeight
+                    self.detailViewConstraint.constant = self.detailView.frame.height
                     self.view.layoutIfNeeded()
                 } completion: { (_) in
                 }
             }
             
             // CLOSE DETAIL
-//            if (imageView.center.y > view.center.y + 30) || (deltaY < -30) || (topPoint.y + 30 < currentLocation.y) {
+            if !detailView.isHidden && (imageViewCentetY > viewCenterY + 20) {
+                
+                gestureRecognizer.state = .ended
                 
-//                if detailView.isShow() {
-//                    detailView.hide()
-//                    gestureRecognizer.state = .ended
-//                }
-//            }
+                UIView.animate(withDuration: 0.3) {
+                    self.imageViewTopConstraint.constant = 0
+                    self.imageViewBottomConstraint.constant = 0
+                    self.detailViewConstraint.constant = 0
+                    self.view.layoutIfNeeded()
+                } completion: { (_) in
+                    self.detailView.hide()
+                }
+            }
             
         default:
             break