Skip to content
Navigation Menu
{{ message }}
This repository was archived by the owner on Nov 15, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathConfigViewController.swift
More file actions
241 lines (217 loc) · 10.1 KB
/
Copy pathConfigViewController.swift
File metadata and controls
241 lines (217 loc) · 10.1 KB
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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
//
// ConfigViewController.swift
// Example
//
// Created by 蒋惠 on 2019/11/8.
// Copyright © 2019 AnyImageProject.org. All rights reserved.
//
import UIKit
import AnyImageEditor
final class ConfigViewController: UITableViewController {
var config = ImageEditorController.PhotoConfig()
override func viewDidLoad() {
super.viewDidLoad()
self.title = "AnyImageEditor"
setupNavigation()
}
private func setupNavigation() {
let title = BundleHelper.localizedString(key: "Open picker")
navigationItem.rightBarButtonItem = UIBarButtonItem(title: title, style: .done, target: self, action: #selector(openPickerTapped))
}
@objc private func openPickerTapped() {
let image = UIImage(named: "test-image")!
let controller = ImageEditorController(image: image, config: config, delegate: self)
controller.modalPresentationStyle = .fullScreen
present(controller, animated: true, completion: nil)
}
// MARK: - Table view data source
override func numberOfSections(in tableView: UITableView) -> Int {
return 1
}
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return RowType.allCases.count
}
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell: UITableViewCell
if let reuseCell = tableView.dequeueReusableCell(withIdentifier: "Cell") {
cell = reuseCell
} else {
cell = UITableViewCell(style: .value1, reuseIdentifier: "Cell")
}
let rowType = RowType.allCases[indexPath.row]
cell.textLabel?.text = BundleHelper.localizedString(key: rowType.title)
cell.detailTextLabel?.text = rowType.defaultValue
return cell
}
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
tableView.deselectRow(at: indexPath, animated: true)
let rowType = RowType.allCases[indexPath.row]
switch rowType {
case .editOptions:
editOptionsTapped()
case .penWidth:
penWidthTapped()
case .mosaicOptions:
mosaicOptionsTapped()
case .mosaicWidth:
mosaicWidthTapped()
case .mosaicLevel:
mosaicLevelTapped()
}
}
}
extension ConfigViewController {
private func editOptionsTapped() {
let indexPath = RowType.editOptions.indexPath
let alert = UIAlertController(title: "EditOptions", message: nil, preferredStyle: .alert)
alert.addAction(UIAlertAction(title: "Pen+Crop+Mosaic", style: .default, handler: { [weak self] (_) in
self?.config.editOptions = [.pen, .crop, .mosaic]
self?.tableView.cellForRow(at: indexPath)?.detailTextLabel?.text = "Pen+Crop+Mosaic"
}))
alert.addAction(UIAlertAction(title: "Pen", style: .default, handler: { [weak self] (_) in
self?.config.editOptions = [.pen]
self?.tableView.cellForRow(at: indexPath)?.detailTextLabel?.text = "Pen"
}))
alert.addAction(UIAlertAction(title: "Crop", style: .default, handler: { [weak self] (_) in
self?.config.editOptions = [.crop]
self?.tableView.cellForRow(at: indexPath)?.detailTextLabel?.text = "Crop"
}))
alert.addAction(UIAlertAction(title: "Mosaic", style: .default, handler: { [weak self] (_) in
self?.config.editOptions = [.mosaic]
self?.tableView.cellForRow(at: indexPath)?.detailTextLabel?.text = "Mosaic"
}))
alert.addAction(UIAlertAction(title: "Cancel", style: .cancel, handler: nil))
present(alert, animated: true, completion: nil)
}
private func penWidthTapped() {
let indexPath = RowType.penWidth.indexPath
let alert = UIAlertController(title: "PenWidth", message: nil, preferredStyle: .alert)
alert.addAction(UIAlertAction(title: "2.5", style: .default, handler: { [weak self] (_) in
self?.config.penWidth = 2.5
self?.tableView.cellForRow(at: indexPath)?.detailTextLabel?.text = "2.5"
}))
alert.addAction(UIAlertAction(title: "5.0", style: .default, handler: { [weak self] (_) in
self?.config.penWidth = 5.0
self?.tableView.cellForRow(at: indexPath)?.detailTextLabel?.text = "5.0"
}))
alert.addAction(UIAlertAction(title: "7.5", style: .default, handler: { [weak self] (_) in
self?.config.penWidth = 7.5
self?.tableView.cellForRow(at: indexPath)?.detailTextLabel?.text = "7.5"
}))
alert.addAction(UIAlertAction(title: "10.0", style: .default, handler: { [weak self] (_) in
self?.config.penWidth = 10.0
self?.tableView.cellForRow(at: indexPath)?.detailTextLabel?.text = "10.0"
}))
alert.addAction(UIAlertAction(title: "Cancel", style: .cancel, handler: nil))
present(alert, animated: true, completion: nil)
}
private func mosaicOptionsTapped() {
let indexPath = RowType.mosaicOptions.indexPath
let alert = UIAlertController(title: "MosaicOptions", message: nil, preferredStyle: .alert)
alert.addAction(UIAlertAction(title: "Default+Colorful", style: .default, handler: { [weak self] (_) in
self?.config.mosaicOptions = [.default, .colorful]
self?.tableView.cellForRow(at: indexPath)?.detailTextLabel?.text = "Default+Colorful"
}))
alert.addAction(UIAlertAction(title: "Default", style: .default, handler: { [weak self] (_) in
self?.config.mosaicOptions = [.default]
self?.tableView.cellForRow(at: indexPath)?.detailTextLabel?.text = "Default"
}))
alert.addAction(UIAlertAction(title: "Colorful", style: .default, handler: { [weak self] (_) in
self?.config.mosaicOptions = [.colorful]
self?.tableView.cellForRow(at: indexPath)?.detailTextLabel?.text = "Colorful"
}))
alert.addAction(UIAlertAction(title: "Cancel", style: .cancel, handler: nil))
present(alert, animated: true, completion: nil)
}
private func mosaicWidthTapped() {
let indexPath = RowType.mosaicWidth.indexPath
let alert = UIAlertController(title: "MosaicWidth", message: nil, preferredStyle: .alert)
alert.addAction(UIAlertAction(title: "15.0", style: .default, handler: { [weak self] (_) in
self?.config.mosaicWidth = 15.0
self?.tableView.cellForRow(at: indexPath)?.detailTextLabel?.text = "15.0"
}))
alert.addAction(UIAlertAction(title: "20.0", style: .default, handler: { [weak self] (_) in
self?.config.mosaicWidth = 20.0
self?.tableView.cellForRow(at: indexPath)?.detailTextLabel?.text = "20.0"
}))
alert.addAction(UIAlertAction(title: "25.0", style: .default, handler: { [weak self] (_) in
self?.config.mosaicWidth = 25.0
self?.tableView.cellForRow(at: indexPath)?.detailTextLabel?.text = "25.0"
}))
alert.addAction(UIAlertAction(title: "30.0", style: .default, handler: { [weak self] (_) in
self?.config.mosaicWidth = 30.0
self?.tableView.cellForRow(at: indexPath)?.detailTextLabel?.text = "30.0"
}))
alert.addAction(UIAlertAction(title: "Cancel", style: .cancel, handler: nil))
present(alert, animated: true, completion: nil)
}
private func mosaicLevelTapped() {
let indexPath = RowType.mosaicLevel.indexPath
let alert = UIAlertController(title: "MosaicLevel", message: nil, preferredStyle: .alert)
alert.addAction(UIAlertAction(title: "20", style: .default, handler: { [weak self] (_) in
self?.config.mosaicLevel = 20
self?.tableView.cellForRow(at: indexPath)?.detailTextLabel?.text = "20"
}))
alert.addAction(UIAlertAction(title: "30", style: .default, handler: { [weak self] (_) in
self?.config.mosaicLevel = 30
self?.tableView.cellForRow(at: indexPath)?.detailTextLabel?.text = "30"
}))
alert.addAction(UIAlertAction(title: "40", style: .default, handler: { [weak self] (_) in
self?.config.mosaicLevel = 40
self?.tableView.cellForRow(at: indexPath)?.detailTextLabel?.text = "40"
}))
alert.addAction(UIAlertAction(title: "50", style: .default, handler: { [weak self] (_) in
self?.config.mosaicLevel = 50
self?.tableView.cellForRow(at: indexPath)?.detailTextLabel?.text = "50"
}))
alert.addAction(UIAlertAction(title: "Cancel", style: .cancel, handler: nil))
present(alert, animated: true, completion: nil)
}
}
extension ConfigViewController: ImageEditorPhotoDelegate {
func imageEditorDidFinishEdit(photo: UIImage) {
let controller = ResultViewController()
controller.imageView.image = photo
navigationController?.pushViewController(controller, animated: false)
}
}
extension ConfigViewController {
enum RowType: Int, CaseIterable {
case editOptions = 0
case penWidth
case mosaicOptions
case mosaicWidth
case mosaicLevel
var title: String {
switch self {
case .editOptions:
return "EditOptions"
case .penWidth:
return "PenWidth"
case .mosaicOptions:
return "MosaicOptions"
case .mosaicWidth:
return "MosaicWidth"
case .mosaicLevel:
return "MosaicLevel"
}
}
var defaultValue: String {
switch self {
case .editOptions:
return "Pen+Crop+Mosaic"
case .penWidth:
return "5.0"
case .mosaicOptions:
return "Default+Colorful"
case .mosaicWidth:
return "15.0"
case .mosaicLevel:
return "30"
}
}
var indexPath: IndexPath {
return IndexPath(row: rawValue, section: 0)
}
}
}
You can’t perform that action at this time.
