瀏覽代碼

ensure small landscape image messages without text are scaled correctly

cyberta 4 年之前
父節點
當前提交
cd10741733
共有 1 個文件被更改,包括 9 次插入5 次删除
  1. 9 5
      deltachat-ios/Chat/Views/Cells/ImageTextCell.swift

+ 9 - 5
deltachat-ios/Chat/Views/Cells/ImageTextCell.swift

@@ -4,7 +4,7 @@ import DcCore
 import SDWebImage
 
 class ImageTextCell: BaseMessageCell {
-
+    let minImageWidth: CGFloat = 175
     var imageHeightConstraint: NSLayoutConstraint?
     var imageWidthConstraint: NSLayoutConstraint?
 
@@ -112,9 +112,9 @@ class ImageTextCell: BaseMessageCell {
         self.imageWidthConstraint?.isActive = false
         
         // check if image has the allowed minimal width
-        if width < 175 {
-            height = (height / width) * 175
-            width = 175
+        if width < minImageWidth {
+            height = (height / width) * minImageWidth
+            width = minImageWidth
         }
         
         if  height > width {
@@ -138,7 +138,11 @@ class ImageTextCell: BaseMessageCell {
                 self.imageWidthConstraint = self.contentImageView.widthAnchor.constraint(lessThanOrEqualTo: self.contentImageView.heightAnchor,
                                                                                          multiplier: width/height)
             } else {
-                self.imageWidthConstraint = self.contentImageView.widthAnchor.constraint(lessThanOrEqualToConstant: width)
+                if width == minImageWidth {
+                    self.imageWidthConstraint = self.contentImageView.widthAnchor.constraint(equalToConstant: width)
+                } else {
+                    self.imageWidthConstraint = self.contentImageView.widthAnchor.constraint(lessThanOrEqualToConstant: width)
+                }
                 self.imageHeightConstraint = self.contentImageView.heightAnchor.constraint(
                     lessThanOrEqualTo: self.contentImageView.widthAnchor,
                     multiplier: height / width