LayoutDefine.swift 1004 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. //
  2. // LayoutDefine.swift
  3. // TXLiteAVDemo
  4. //
  5. // Created by gg on 2021/3/15.
  6. // Copyright © 2021 Tencent. All rights reserved.
  7. //
  8. import UIKit
  9. public let ScreenWidth = UIScreen.main.bounds.width
  10. public let ScreenHeight = UIScreen.main.bounds.height
  11. public let kDeviceIsIphoneX : Bool = {
  12. if UIDevice.current.userInterfaceIdiom == .pad {
  13. return false
  14. }
  15. let size = UIScreen.main.bounds.size
  16. let notchValue = Int(size.width/size.height*100)
  17. if notchValue == 216 || notchValue == 46 {
  18. return true
  19. }
  20. return false
  21. }()
  22. public let kDeviceSafeTopHeight : CGFloat = {
  23. if kDeviceIsIphoneX {
  24. return 44
  25. }
  26. else {
  27. return 20
  28. }
  29. }()
  30. public let kDeviceSafeBottomHeight : CGFloat = {
  31. if kDeviceIsIphoneX {
  32. return 34
  33. }
  34. else {
  35. return 0
  36. }
  37. }()
  38. public func convertPixel(w:CGFloat) -> CGFloat {
  39. return w/375.0*ScreenWidth
  40. }
  41. public func convertPixel(h:CGFloat) -> CGFloat {
  42. return h/812.0*ScreenHeight
  43. }