UIWindow+orientation.swift 893 B

123456789101112131415161718192021222324252627282930313233343536
  1. //
  2. // UIWindow+orientation.swift
  3. // NotificationBannerSwift
  4. //
  5. // Created by gabmarfer on 15/10/2019.
  6. //
  7. import UIKit
  8. extension UIWindow {
  9. public var width: CGFloat {
  10. let orientation = UIDevice.current.orientation
  11. switch orientation {
  12. case .landscapeLeft, .landscapeRight:
  13. return max(frame.width, frame.height)
  14. case .portrait, .portraitUpsideDown:
  15. return min(frame.width, frame.height)
  16. default:
  17. return frame.width
  18. }
  19. }
  20. public var height: CGFloat {
  21. let orientation = UIDevice.current.orientation
  22. switch orientation {
  23. case .landscapeLeft, .landscapeRight:
  24. return min(frame.width, frame.height)
  25. case .portrait, .portraitUpsideDown:
  26. return max(frame.width, frame.height)
  27. default:
  28. return frame.height
  29. }
  30. }
  31. }