Skip to content

Commit

Permalink
use new way to check the screen have notch
Browse files Browse the repository at this point in the history
  • Loading branch information
DuckDeck committed Jun 29, 2020
1 parent 7d4e4b0 commit 3881fbe
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 23 deletions.
39 changes: 19 additions & 20 deletions Sources/Tool.swift
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ extension UIDevice{
case "iPod4,1": return "iPod touch 4"
case "iPod5,1": return "iPod Touch 5"
case "iPod7,1": return "iPod Touch 6"
case "iPod9,1": return "iPod Touch 7"
// iPhone
case "iPhone1,1": return "iPhone"
case "iPhone1,2": return "iPhone 3G"
Expand All @@ -209,6 +210,12 @@ extension UIDevice{
case "iPhone10,1", "iPhone10,4": return "iPhone 8"
case "iPhone10,2", "iPhone10,5": return "iPhone 8 Plus"
case "iPhone10,3", "iPhone10,6": return "iPhone X"
case "iPhone11,2": return "iPhone XS"
case "iPhone11,6": return "iPhone XS MAX"
case "iPhone11,8": return "iPhone XR"
case "iPhone12,1": return "iPhone 11"
case "iPhone12,3": return "iPhone 11 Pro"
case "iPhone12,5": return "iPhone 11 Pro max"
// iPad
case "iPad1,1": return "iPad"
case "iPad2,1", "iPad2,2", "iPad2,3", "iPad2,4":return "iPad 2"
Expand All @@ -233,31 +240,23 @@ extension UIDevice{
default: return identifier
}
}


}

//获取设备类型,根据屏的w
enum DeviceResution{
case Res414X896,Res375X812,Res320X568,Res414X736,Res375X667
}


extension UIDevice{
static var screenResution:DeviceResution{
let res = UIScreen.main.bounds
if res.height == 896{
return DeviceResution.Res414X896
}
else if res.height == 812{
return DeviceResution.Res375X812
}
else if res.height == 736{
return DeviceResution.Res375X812
}
else if res.height == 667{
return DeviceResution.Res375X667
public static var isNotchScreen:Bool{
if UIDevice.current.userInterfaceIdiom == .pad{
return false
}
return DeviceResution.Res320X568
let size = UIScreen.main.bounds.size
let notchValue: Int = Int(size.width/size.height * 100)
if 216 == notchValue || 46 == notchValue {

return true
}

return false
}
}

4 changes: 2 additions & 2 deletions Sources/ViewChaos.swift
Original file line number Diff line number Diff line change
Expand Up @@ -353,8 +353,8 @@ class ViewChaos: UIView {
viewBound.layer.borderWidth = 3
viewBound.layer.borderColor = UIColor.black.cgColor //View的边界黑色,这个应该可以切换
viewBound.layer.zPosition = CGFloat(Float.greatestFiniteMagnitude)

let infoTop:CGFloat = (UIDevice.screenResution == .Res414X736 || UIDevice.screenResution == .Res414X896) ? 36 : 0
let infoTop:CGFloat = UIDevice.isNotchScreen ? 36 : 0
windowInfo = UIWindow(frame: CGRect(x: 0, y: infoTop, width: UIScreen.main.bounds.width, height: 50))
windowInfo.backgroundColor = UIColor(red: 0.0, green: 0.898, blue: 0.836, alpha: 0.7)
windowInfo.isHidden = true
Expand Down
2 changes: 1 addition & 1 deletion Sources/ZoomView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ class ZoomViewBrace: UIView {
override init(frame: CGRect) {
super.init(frame: frame)
self.frame = UIScreen.main.bounds
let infoTop:CGFloat = (UIDevice.screenResution == .Res414X736 || UIDevice.screenResution == .Res414X896) ? 50 : 0
let infoTop:CGFloat = UIDevice.isNotchScreen ? 50 : 0
lblPixelColor.frame = CGRect(x: 0, y: infoTop, width: UIScreen.main.bounds.size.width, height: 22)
lblPixelColor.backgroundColor = UIColor(red: 0.0, green: 0.898, blue: 0.836, alpha: 0.7)
lblPixelColor.textColor = UIColor.black
Expand Down

0 comments on commit 3881fbe

Please sign in to comment.