فهرست منبع

YYCGUtilities: Fixed aspect fill rect calculation issue

ibireme 9 سال پیش
والد
کامیت
665df41ddd
1فایلهای تغییر یافته به همراه11 افزوده شده و 4 حذف شده
  1. 11 4
      YYWebImage/Categories/UIImage+YYWebImage.m

+ 11 - 4
YYWebImage/Categories/UIImage+YYWebImage.m

@@ -49,11 +49,18 @@ static CGRect _YYCGRectFitWithContentMode(CGRect rect, CGSize size, UIViewConten
                 rect.size = CGSizeZero;
             } else {
                 CGFloat scale;
-                if (size.width / size.height < rect.size.width / rect.size.height &&
-                    mode == UIViewContentModeScaleAspectFit) {
-                    scale = rect.size.height / size.height;
+                if (mode == UIViewContentModeScaleAspectFit) {
+                    if (size.width / size.height < rect.size.width / rect.size.height) {
+                        scale = rect.size.height / size.height;
+                    } else {
+                        scale = rect.size.width / size.width;
+                    }
                 } else {
-                    scale = rect.size.width / size.width;
+                    if (size.width / size.height < rect.size.width / rect.size.height) {
+                        scale = rect.size.width / size.width;
+                    } else {
+                        scale = rect.size.height / size.height;
+                    }
                 }
                 size.width *= scale;
                 size.height *= scale;