/
CropAuxiliaryIndicatorView+Accessibility.swift
116 lines (105 loc) · 5.5 KB
/
CropAuxiliaryIndicatorView+Accessibility.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
//
// CropAuxiliaryIndicatorView+Accessibility.swift
// Mantis
//
// Created by Yingtao Guo on 3/1/23.
//
import UIKit
extension CropAuxiliaryIndicatorView {
private func ifAccessibilityHelperNeeded() -> Bool {
return UIAccessibility.isVoiceOverRunning
|| UIAccessibility.isSwitchControlRunning
|| UIAccessibility.isSpeakScreenEnabled
}
func setupAccessibilityHelperViews () {
guard ifAccessibilityHelperNeeded() else {
return
}
accessibilityHelperViews.removeAll()
for index in 0..<8 {
let helperView = UIView(frame: .zero)
helperView.isAccessibilityElement = true
addSubview(helperView)
accessibilityHelperViews.append(helperView)
guard let handleType = CropViewAuxiliaryIndicatorHandleType(rawValue: index + 1) else {
continue
}
switch handleType {
case .topLeft:
helperView.accessibilityLabel = LocalizedHelper.getString("Mantis.Top left crop handle", value: "Top left crop handle")
case .top:
helperView.accessibilityLabel = LocalizedHelper.getString("Mantis.Top crop handle", value: "Top crop handle")
case .topRight:
helperView.accessibilityLabel = LocalizedHelper.getString("Mantis.Top right crop handle", value: "Top right crop handle")
case .right:
helperView.accessibilityLabel = LocalizedHelper.getString("Mantis.Right crop handle", value: "Right crop handle")
case .bottomRight:
helperView.accessibilityLabel = LocalizedHelper.getString("Mantis.Bottom right crop handle", value: "Bottom right crop handle")
case .bottom:
helperView.accessibilityLabel = LocalizedHelper.getString("Mantis.Bottom crop handle", value: "Bottom crop handle")
case .bottomLeft:
helperView.accessibilityLabel = LocalizedHelper.getString("Mantis.Bottom left crop handle", value: "Bottom left crop handle")
case .left:
helperView.accessibilityLabel = LocalizedHelper.getString("Mantis.Left crop handle", value: "Left crop handle")
case .none:
break
}
helperView.accessibilityHint = LocalizedHelper.getString("Mantis.Double tap and hold to adjust crop area",
value: "Double tap and hold to adjust crop area")
}
}
func layoutAccessibilityHelperViews() {
guard ifAccessibilityHelperNeeded() else {
return
}
for (index, helperView) in accessibilityHelperViews.enumerated() {
guard let handleType = CropViewAuxiliaryIndicatorHandleType(rawValue: index + 1) else {
continue
}
switch handleType {
case .topLeft:
helperView.frame = CGRect(x: -cropBoxHotAreaUnit/2,
y: -cropBoxHotAreaUnit/2,
width: cropBoxHotAreaUnit,
height: cropBoxHotAreaUnit)
case .top:
helperView.frame = CGRect(x: cropBoxHotAreaUnit/2,
y: -cropBoxHotAreaUnit/2,
width: bounds.width - cropBoxHotAreaUnit,
height: cropBoxHotAreaUnit)
case .topRight:
helperView.frame = CGRect(x: bounds.width - cropBoxHotAreaUnit/2,
y: -cropBoxHotAreaUnit/2,
width: cropBoxHotAreaUnit,
height: cropBoxHotAreaUnit)
case .right:
helperView.frame = CGRect(x: bounds.width - cropBoxHotAreaUnit/2,
y: cropBoxHotAreaUnit/2,
width: cropBoxHotAreaUnit,
height: bounds.height - cropBoxHotAreaUnit)
case .bottomRight:
helperView.frame = CGRect(x: bounds.width - cropBoxHotAreaUnit/2,
y: bounds.height - cropBoxHotAreaUnit/2,
width: cropBoxHotAreaUnit,
height: cropBoxHotAreaUnit)
case .bottom:
helperView.frame = CGRect(x: cropBoxHotAreaUnit/2,
y: bounds.height - cropBoxHotAreaUnit/2,
width: bounds.width - cropBoxHotAreaUnit,
height: cropBoxHotAreaUnit)
case .bottomLeft:
helperView.frame = CGRect(x: -cropBoxHotAreaUnit/2,
y: bounds.height - cropBoxHotAreaUnit/2,
width: cropBoxHotAreaUnit,
height: cropBoxHotAreaUnit)
case .left:
helperView.frame = CGRect(x: -cropBoxHotAreaUnit/2,
y: cropBoxHotAreaUnit/2,
width: cropBoxHotAreaUnit,
height: bounds.height - cropBoxHotAreaUnit)
case .none:
break
}
}
}
}