Skip to content

Commit

Permalink
修复plus机型判断问题
Browse files Browse the repository at this point in the history
  • Loading branch information
lixiang1994 committed Mar 9, 2022
1 parent e13548f commit 34347f4
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
2 changes: 1 addition & 1 deletion AutoInch.podspec
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Pod::Spec.new do |s|

s.name = "AutoInch"
s.version = "2.4.0"
s.version = "2.4.1"
s.summary = "优雅的iPhone 等比例/精准 适配工具"

s.homepage = "https://github.com/lixiang1994/AutoInch"
Expand Down
19 changes: 18 additions & 1 deletion Sources/Screen.swift
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,8 @@ extension ScreenWrapper {
public enum Screen {

public static var isZoomedMode: Bool {
UIScreen.main.scale != UIScreen.main.nativeScale
guard !isPlus else { return UIScreen.main.bounds.width == 375 }
return UIScreen.main.scale != UIScreen.main.nativeScale
}

static var size: CGSize {
Expand All @@ -123,6 +124,7 @@ public enum Screen {
case _428 = 428

public static var current: Width {
guard !isPlus else { return ._414 }
return Width(rawValue: nativeSize.width / scale) ?? .unknown
}
}
Expand All @@ -139,6 +141,7 @@ public enum Screen {
case _926 = 926

public static var current: Height {
guard !isPlus else { return ._736 }
return Height(rawValue: nativeSize.height / scale) ?? .unknown
}
}
Expand All @@ -156,6 +159,11 @@ public enum Screen {
case _6_7 = 6.7

public static var current: Inch {
guard !isPlus else {
// Plus 机型比较特殊 下面公式无法正确计算出尺寸
return ._5_5
}

switch (nativeSize.width / scale, nativeSize.height / scale, scale) {
case (320, 480, 2):
return ._3_5
Expand Down Expand Up @@ -200,6 +208,11 @@ public enum Screen {
case full

public static var current: Level {
guard !isPlus else {
// Plus 机型比较特殊 下面公式无法正确计算出尺寸
return .regular
}

switch (nativeSize.width / scale, nativeSize.height / scale) {
case (320, 480):
return .compact
Expand All @@ -215,6 +228,10 @@ public enum Screen {
}
}
}

private static var isPlus: Bool {
return nativeSize.equalTo(.init(width: 1080, height: 1920))
}
}

extension Screen {
Expand Down

0 comments on commit 34347f4

Please sign in to comment.