|
@@ -157,7 +157,17 @@ extension TSAIExpandImageVC {
|
|
var expandWidth: CGFloat
|
|
var expandWidth: CGFloat
|
|
var expandHeight: CGFloat
|
|
var expandHeight: CGFloat
|
|
|
|
|
|
- if targetAspectRatio > imageAspectRatio {
|
|
|
|
|
|
+// if targetAspectRatio > imageAspectRatio {
|
|
|
|
+// // 以宽度为基准
|
|
|
|
+// expandWidth = maxSize.width
|
|
|
|
+// expandHeight = expandWidth / targetAspectRatio
|
|
|
|
+// }else {
|
|
|
|
+// // 以高度为基准
|
|
|
|
+// expandHeight = maxSize.height
|
|
|
|
+// expandWidth = expandHeight * targetAspectRatio
|
|
|
|
+// }
|
|
|
|
+
|
|
|
|
+ if targetAspectRatio >= 1.0 {
|
|
// 以宽度为基准
|
|
// 以宽度为基准
|
|
expandWidth = maxSize.width
|
|
expandWidth = maxSize.width
|
|
expandHeight = expandWidth / targetAspectRatio
|
|
expandHeight = expandWidth / targetAspectRatio
|
|
@@ -168,8 +178,8 @@ extension TSAIExpandImageVC {
|
|
}
|
|
}
|
|
|
|
|
|
// 确保扩图区域不超过最大限制(100%)
|
|
// 确保扩图区域不超过最大限制(100%)
|
|
- let maxExpandWidth = view.bounds.width
|
|
|
|
- let maxExpandHeight = view.bounds.height
|
|
|
|
|
|
+ let maxExpandWidth = maxSize.width
|
|
|
|
+ let maxExpandHeight = maxSize.height
|
|
print("\n")
|
|
print("\n")
|
|
expandWidth = min(expandWidth, maxExpandWidth)
|
|
expandWidth = min(expandWidth, maxExpandWidth)
|
|
expandHeight = min(expandHeight, maxExpandHeight)
|
|
expandHeight = min(expandHeight, maxExpandHeight)
|
|
@@ -178,11 +188,14 @@ extension TSAIExpandImageVC {
|
|
print("expandHeight=\(expandHeight)")
|
|
print("expandHeight=\(expandHeight)")
|
|
print("\n")
|
|
print("\n")
|
|
|
|
|
|
|
|
+ let difference = abs(targetAspectRatio - imageAspectRatio) <= 0.01
|
|
|
|
+ print("targetAspectRatio=\(targetAspectRatio),imageAspectRatio=\(imageAspectRatio),difference=\(difference)")
|
|
|
|
+
|
|
// 使用 SnapKit 更新约束
|
|
// 使用 SnapKit 更新约束
|
|
expandAreaView.updateExpandAreaView(width: expandWidth, height: expandHeight)
|
|
expandAreaView.updateExpandAreaView(width: expandWidth, height: expandHeight)
|
|
let imageRatio = min(expandWidth/imageSize.width,expandHeight/imageSize.height)
|
|
let imageRatio = min(expandWidth/imageSize.width,expandHeight/imageSize.height)
|
|
var scaleFactor = 1.0
|
|
var scaleFactor = 1.0
|
|
- if targetAspectRatio == 1.0,imageAspectRatio == 1.0 {
|
|
|
|
|
|
+ if difference {
|
|
scaleFactor = 0.67
|
|
scaleFactor = 0.67
|
|
}
|
|
}
|
|
|
|
|
|
@@ -197,7 +210,8 @@ extension TSAIExpandImageVC {
|
|
let ws = expandWidth/imageViewW - 1.0
|
|
let ws = expandWidth/imageViewW - 1.0
|
|
let hs = expandHeight/imageViewH - 1.0
|
|
let hs = expandHeight/imageViewH - 1.0
|
|
|
|
|
|
- if targetAspectRatio == 1.0,imageAspectRatio == 1.0 {
|
|
|
|
|
|
+
|
|
|
|
+ if difference {
|
|
photoExpand = UIEdgeInsets(top: 0.25, left: 0.25, bottom: 0.25, right: 0.25)
|
|
photoExpand = UIEdgeInsets(top: 0.25, left: 0.25, bottom: 0.25, right: 0.25)
|
|
}else{
|
|
}else{
|
|
photoExpand = UIEdgeInsets(top: hs/2.0, left: ws/2.0, bottom: hs/2.0, right: ws/2.0)
|
|
photoExpand = UIEdgeInsets(top: hs/2.0, left: ws/2.0, bottom: hs/2.0, right: ws/2.0)
|