CameraGlobals.swift 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. //
  2. // CameraGlobals.swift
  3. // ALCameraViewController
  4. //
  5. // Created by Alex Littlejohn on 2016/02/16.
  6. // Copyright © 2016 zero. All rights reserved.
  7. //
  8. // Modified by Kevin Kieffer on 2019/08/06. Changes as follows:
  9. // Adding adjustable number of columns for library view, based on .ipad or smaller device
  10. import UIKit
  11. import AVFoundation
  12. internal let itemSpacing: CGFloat = 1
  13. internal let scale = UIScreen.main.scale
  14. public class CameraGlobals {
  15. public static let shared = CameraGlobals()
  16. public var bundle = Bundle(for: CameraViewController.self)
  17. public var stringsTable = "CameraView"
  18. public var defaultCameraPosition = AVCaptureDevice.Position.back
  19. public static let MAX_COLUMNS : Int = {
  20. switch UIDevice.current.userInterfaceIdiom {
  21. case .pad:
  22. return 20
  23. default:
  24. return 10
  25. }
  26. }()
  27. public static let MIN_COLUMNS = 2
  28. public static let DEFAULT_COLUMNS : Int = {
  29. switch UIDevice.current.userInterfaceIdiom {
  30. case .pad:
  31. return 8
  32. default:
  33. return 4
  34. }
  35. }()
  36. public func photoLibraryThumbnailSize(withColumns columns : Int) -> CGSize {
  37. let cols = CGFloat(columns)
  38. let thumbnailDimension = (UIScreen.main.bounds.width - ((cols * itemSpacing) - itemSpacing))/cols
  39. return CGSize(width: thumbnailDimension, height: thumbnailDimension)
  40. }
  41. }