/
BackCameraType+Extension.swift
61 lines (61 loc) · 2.02 KB
/
BackCameraType+Extension.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import UIKit
/**
* BackCameraType - extensions
*/
extension BackCameraType {
/**
* Returns the needed width for the entire ZoomSwitcher
*/
public var width: CGFloat {
let numOfLenses: CGFloat = .init(self.numberOfLenses)
return (numOfLenses * ZoomSwitcherButton.buttonWidth) + abs(numOfLenses - 1) * ZoomSwitcherButton.spaceBetween
}
/**
* Returns a string with all focalTypes in a backCameraType
* ## Example:
* print(BackCameraType.triple.description) // "Ultra wide, wide angle, tele"
*/
public var description: String {
focalTypes.map { "\($0.rawValue)" }.joined(separator: ", ")
//return FocalType.allCases.map { "\($0.rawValue)" }.joined(separator: ", ")
}
/**
* The various back cameras on the various iPhones
*/
public var focalTypes: [FocalType] {
switch self {
case .singleWide: return [.wide] // iPhone 6, 7, 8 etc
case .dualUltraWideAndWide: return [.ultraWide, .wide] // iPhone X
case .dualWideAndTele: return [.wide, .tele] // iPhone 11
case .triple: return [.ultraWide, .wide, .tele] // iPhone 11 pro
}
}
/**
* Returns the backCameraType for the device
*/
public static var backCameraType: BackCameraType {
//Swift.print("UIDevice.modelName: \(UIDevice.init().modelName)")
let device: UIDevice = .init()
switch device.modelName {
case .iPhone11Pro, .iPhone11ProMax:
return .triple
case .iPhone11:
return .dualUltraWideAndWide
case .iPhoneX, .iPhoneXS, .iPhoneXSMax, .iPhone7Plus, .iPhone8Plus, .iPhoneXR:
return .dualWideAndTele
default:
return .singleWide
}
}
/**
* Returns the amount of lenses for the backCameraType
*/
public var numberOfLenses: Int { focalTypes.count }
/**
* Tripple back cameras the default lense button is in the center, all else is to the left
* - Note: 0.5X, 1.0x, 2.0x
*/
public var defaultLenseIndex: Int {
BackCameraType.backCameraType == .triple ? 1 : 0
}
}