-
Notifications
You must be signed in to change notification settings - Fork 26
/
FAQView.swift
executable file
·657 lines (553 loc) · 25 KB
/
FAQView.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
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
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
//
// FAQView.swift
// FAQView
//
// Created by Mukesh Thawani on 12/11/16.
// Copyright © 2016 Mukesh Thawani. All rights reserved.
//
import Foundation
public class FAQView: UIView {
// MARK: Public Properties
public var items: [FAQItem]
public var questionTextColor: UIColor! {
get {
return configuration.questionTextColor
}
set(value) {
configuration.questionTextColor = value
}
}
public var answerTextColor: UIColor! {
get {
return configuration.answerTextColor
}
set(value) {
configuration.answerTextColor = value
}
}
public var questionTextFont: UIFont! {
get {
return configuration.questionTextFont
}
set(value) {
configuration.questionTextFont = value
}
}
public var answerTextFont: UIFont! {
get {
return configuration.answerTextFont
}
set(value) {
configuration.answerTextFont = value
}
}
public var titleLabelTextColor: UIColor! {
get {
return configuration.titleTextColor
}
set(value) {
configuration.titleTextColor = value
titleLabel.textColor = configuration.titleTextColor
}
}
public var titleLabelTextFont: UIFont! {
get {
return configuration.titleTextFont
}
set(value) {
configuration.titleTextFont = value
titleLabel.font = configuration.titleTextFont
}
}
public var titleLabelBackgroundColor: UIColor! {
get {
return configuration.titleLabelBackgroundColor
}
set(value) {
configuration.titleLabelBackgroundColor = value
titleLabel.backgroundColor = configuration.titleLabelBackgroundColor
}
}
public var viewBackgroundColor: UIColor! {
get {
return configuration.viewBackgroundColor
}
set(value) {
configuration.viewBackgroundColor = value
self.backgroundColor = configuration.viewBackgroundColor
}
}
public var cellBackgroundColor: UIColor! {
get {
return configuration.cellBackgroundColor
}
set(value) {
configuration.cellBackgroundColor = value
}
}
public var separatorColor: UIColor! {
get {
return configuration.separatorColor
}
set(value) {
configuration.separatorColor = value
}
}
public var dataDetectorTypes: UIDataDetectorTypes? {
get {
return configuration.dataDetectorTypes
}
set(value) {
configuration.dataDetectorTypes = value
}
}
public var answerTintColor: UIColor! {
get {
return configuration.tintColor
}
set(value) {
configuration.tintColor = value
}
}
public var indicatorColor: UIColor! {
get {
return configuration.indicatorColor
}
set(value) {
configuration.indicatorColor = value
}
}
public var positionType: Position? {
get {
return configuration.positionType
}
set(value) {
configuration.positionType = value
}
}
// MARK: Internal Properties
var tableView: UITableView = {
let tableview = UITableView()
tableview.translatesAutoresizingMaskIntoConstraints = false
tableview.backgroundColor = UIColor.clear
tableview.allowsSelection = false
tableview.separatorStyle = .none
tableview.estimatedRowHeight = 50
tableview.tableFooterView = UIView()
return tableview
}()
var titleLabel: UILabel = {
let label = UILabel()
label.translatesAutoresizingMaskIntoConstraints = false
label.numberOfLines = 0
label.textAlignment = .center
return label
}()
var expandedCells = [CellOperation]()
var configuration = FAQConfiguration()
var heightAtIndexPath = NSMutableDictionary()
// MARK: Initialization
public init(frame: CGRect,title: String = "Top Queries", items: [FAQItem]) {
self.items = items
super.init(frame: frame)
expandedCells = Array(repeating: CellOperation.collapsed, count: items.count)
setupTitleView(title: title)
setupTableView()
setupView()
self.addSubview(tableView)
self.addSubview(titleLabel)
addConstraintsForTableViewAndTitleLabel()
}
required public init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
// MARK: Internal Methods
func updateSection(_ section: Int) {
if expandedCells[section] == .expanded {
expandedCells[section] = .collapse
} else {
expandedCells[section] = .expand
}
tableView.reloadSections(IndexSet(integer: section), with: .fade)
tableView.scrollToRow(at: IndexPath(row: 0, section: section), at: .top, animated: true)
}
func updateCellOperation(section: Int, cellOperation: CellOperation) {
if cellOperation == .expand {
expandedCells[section] = .expanded
} else if cellOperation == .collapse {
expandedCells[section] = .collapsed
}
}
// MARK: Private Methods
private func setupTitleView(title: String) {
self.titleLabel.textColor = configuration.titleTextColor
self.titleLabel.font = configuration.titleTextFont
self.titleLabel.backgroundColor = configuration.titleLabelBackgroundColor
self.titleLabel.text = title
}
private func setupTableView() {
self.tableView.register(FAQViewCell.self, forCellReuseIdentifier: "cell")
self.tableView.dataSource = self
self.tableView.delegate = self
}
private func setupView() {
self.backgroundColor = configuration.viewBackgroundColor
}
private func addConstraintsForTableViewAndTitleLabel() {
let titleLabelTrailing = NSLayoutConstraint(item: titleLabel, attribute: .trailing, relatedBy: .equal, toItem: self, attribute: .trailingMargin, multiplier: 1, constant: 0)
let titleLabelLeading = NSLayoutConstraint(item: titleLabel, attribute: .leading, relatedBy: .equal, toItem: self, attribute: .leadingMargin, multiplier: 1, constant: 0)
let titleLabelTop = NSLayoutConstraint(item: titleLabel, attribute: .top, relatedBy: .equal, toItem: self, attribute: .topMargin, multiplier: 1, constant: 20)
let tableViewTrailing = NSLayoutConstraint(item: tableView, attribute: .trailing, relatedBy: .equal, toItem: self, attribute: .trailingMargin, multiplier: 1, constant: 0)
let tableViewLeading = NSLayoutConstraint(item: tableView, attribute: .leading, relatedBy: .equal, toItem: self, attribute: .leadingMargin, multiplier: 1, constant: 0)
let tableViewTop = NSLayoutConstraint(item: tableView, attribute: .top, relatedBy: .equal, toItem: titleLabel, attribute: .bottom, multiplier: 1, constant: 15)
let tableViewBottom = NSLayoutConstraint(item: tableView, attribute: .bottom, relatedBy: .equal, toItem: self, attribute: .bottomMargin, multiplier: 1, constant: 0)
NSLayoutConstraint.activate([tableViewTrailing, tableViewLeading, tableViewTop, tableViewBottom, titleLabelLeading, titleLabelTrailing, titleLabelTop])
}
}
extension FAQView: UITableViewDelegate, UITableViewDataSource {
public func tableView(_ tableView: UITableView, estimatedHeightForRowAt indexPath: IndexPath) -> CGFloat {
let height = self.heightAtIndexPath.object(forKey: indexPath)
if ((height) != nil) {
return CGFloat(height as! CGFloat)
} else {
return UITableViewAutomaticDimension
}
}
public func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath) {
let height = cell.frame.size.height
self.heightAtIndexPath.setObject(height, forKey: indexPath as NSCopying)
}
public func numberOfSections(in tableView: UITableView) -> Int {
return items.count
}
public func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 1
}
public func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath) as! FAQViewCell
cell.configuration = configuration
let currentItem = items[indexPath.section]
let cellOperation = expandedCells[indexPath.section]
cell.configure(currentItem: currentItem, indexPath: indexPath, cellOperation: cellOperation)
updateCellOperation(section: indexPath.section, cellOperation: cellOperation)
cell.didSelectQuestion = { [weak self] cell in
guard let faqView = self else {
return
}
faqView.updateSection(indexPath.section)
}
return cell
}
public func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
return 5
}
public func tableView(_ tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat {
return CGFloat.leastNormalMagnitude
}
public func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
let headerView = UIView(frame: CGRect(x: 0, y: 0, width: self.frame.width, height: 5))
headerView.backgroundColor = configuration.separatorColor
return headerView
}
}
public struct FAQItem {
public let question: String
public let answer: String?
public let attributedAnswer: NSAttributedString?
public init(question: String, answer: String) {
self.question = question
self.answer = answer
self.attributedAnswer = nil
}
public init(question: String, attributedAnswer: NSAttributedString) {
self.question = question
self.attributedAnswer = attributedAnswer
self.answer = nil
}
}
public class FAQConfiguration {
public var questionTextColor: UIColor?
public var answerTextColor: UIColor?
public var questionTextFont: UIFont?
public var answerTextFont: UIFont?
public var titleTextColor: UIColor?
public var titleTextFont: UIFont?
public var viewBackgroundColor: UIColor?
public var cellBackgroundColor: UIColor?
public var separatorColor: UIColor?
public var titleLabelBackgroundColor: UIColor?
public var dataDetectorTypes: UIDataDetectorTypes?
public var tintColor: UIColor?
public var indicatorColor: UIColor?
public var positionType: Position?
init() {
defaultValue()
}
func defaultValue() {
self.questionTextFont = UIFont(name: "HelveticaNeue-Bold", size: 16)
self.answerTextFont = UIFont(name: "HelveticaNeue-Light", size: 15)
self.titleTextFont = UIFont(name: "HelveticaNeue-Light", size: 20)
self.titleLabelBackgroundColor = UIColor.clear
let colorValue: CGFloat = 210/255
if #available(iOS 13.0, *) {
self.questionTextColor = .label
} else {
self.questionTextColor = UIColor.black
}
if #available(iOS 13.0, *) {
self.answerTextColor = .label
} else {
self.answerTextColor = UIColor.black
}
if #available(iOS 13.0, *) {
self.titleTextColor = .label
} else {
self.titleTextColor = UIColor.black
}
if #available(iOS 13.0, *) {
self.viewBackgroundColor = .systemGroupedBackground
} else {
self.viewBackgroundColor = UIColor(red: colorValue, green: colorValue, blue: colorValue, alpha: 1)
}
if #available(iOS 13.0, *) {
self.cellBackgroundColor = .secondarySystemGroupedBackground
} else {
self.cellBackgroundColor = UIColor.white
}
if #available(iOS 13.0, *) {
self.separatorColor = .systemGroupedBackground
} else {
self.separatorColor = UIColor(red: colorValue, green: colorValue, blue: colorValue, alpha: 1)
}
if #available(iOS 13.0, *) {
self.indicatorColor = .label
} else {
self.indicatorColor = UIColor.black
}
self.positionType = .left
}
}
class FAQViewCell: UITableViewCell {
// MARK: Internal Properties
var questionLabel: UILabel = {
let label = UILabel()
label.translatesAutoresizingMaskIntoConstraints = false
label.numberOfLines = 0
return label
}()
var answerTextView: UITextView = {
let textView = UITextView()
textView.translatesAutoresizingMaskIntoConstraints = false
textView.backgroundColor = UIColor.clear
textView.isScrollEnabled = false
textView.textContainerInset = UIEdgeInsets(top: 0, left: 0, bottom: 0, right: 0)
textView.isEditable = false
textView.dataDetectorTypes = []
return textView
}()
var indicatorImageView: UIImageView = {
let imageView = UIImageView()
imageView.translatesAutoresizingMaskIntoConstraints = false
imageView.contentMode = .scaleAspectFit
let indicatorImage = UIImage(named: "DownArrow", in: Bundle(for: FAQView.self), compatibleWith: nil)
imageView.image = indicatorImage?.withRenderingMode(.alwaysTemplate)
return imageView
}()
var answerTextViewBottom = NSLayoutConstraint()
var configuration: FAQConfiguration! {
didSet {
setup(with: configuration)
}
}
var didSelectQuestion: ((_ cell: FAQViewCell) ->())?
// MARK: Private Properties
private let actionByQuestionTap = #selector(didTapQuestion)
private var containerView: UIView = {
let view = UIView()
view.translatesAutoresizingMaskIntoConstraints = false
return view
}()
// MARK: Initialization
override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
super.init(style: style, reuseIdentifier: reuseIdentifier)
viewSetup()
}
private func viewSetup() {
selectionSetup()
self.containerView.addSubview(indicatorImageView)
contentView.addSubview(questionLabel)
contentView.addSubview(answerTextView)
contentView.addSubview(containerView)
addLabelConstraints()
}
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
func configure(currentItem: FAQItem, indexPath: IndexPath, cellOperation: CellOperation) {
questionLabel.text = currentItem.question
switch cellOperation {
case .collapsed:
collapse(animated: false)
case .expand:
if let answer = currentItem.answer {
expand(withAnswer: answer, animated: true)
} else if let attributedAnswer = currentItem.attributedAnswer {
expand(withAttributedAnswer: attributedAnswer, animated: true)
}
case .collapse:
collapse(animated: true)
case .expanded:
if let answer = currentItem.answer {
expand(withAnswer: answer, animated: false)
} else if let attributedAnswer = currentItem.attributedAnswer {
expand(withAttributedAnswer: attributedAnswer, animated: false)
}
}
}
// MARK: Private Methods
private func selectionSetup() {
questionLabel.isUserInteractionEnabled = true
indicatorImageView.isUserInteractionEnabled = true
let questionLabelGestureRecognizer = UITapGestureRecognizer(target: self, action
: actionByQuestionTap)
questionLabel.addGestureRecognizer(questionLabelGestureRecognizer)
let imageGestureRecognizer = UITapGestureRecognizer(target: self, action: actionByQuestionTap)
indicatorImageView.addGestureRecognizer(imageGestureRecognizer)
}
private func setup(with configuration: FAQConfiguration) {
self.backgroundColor = configuration.cellBackgroundColor
self.questionLabel.textColor = configuration.questionTextColor
self.answerTextView.textColor = configuration.answerTextColor
self.questionLabel.font = configuration.questionTextFont
self.answerTextView.font = configuration.answerTextFont
if let positionType = configuration.positionType {
setupTextAlignment(position: positionType)
addConstraintsDependOnPositionType(position: positionType)
}
self.indicatorImageView.tintColor = configuration.indicatorColor
if let dataDetectorTypes = configuration.dataDetectorTypes {
self.answerTextView.dataDetectorTypes = dataDetectorTypes
}
if let tintColor = configuration.tintColor {
self.answerTextView.tintColor = tintColor
}
}
private func setupTextAlignment(position:Position){
switch position {
case .left:
self.questionLabel.textAlignment = .left
self.answerTextView.textAlignment = .left
case .right:
self.questionLabel.textAlignment = .right
self.answerTextView.textAlignment = .right
}
}
private func addLabelConstraints() {
let questionLabelTop = NSLayoutConstraint(item: questionLabel, attribute: .top, relatedBy: .equal, toItem: contentView, attribute: .top, multiplier: 1, constant: 10)
let answerTextViewTop = NSLayoutConstraint(item: answerTextView, attribute: .top, relatedBy: .equal, toItem: questionLabel, attribute: .bottom, multiplier: 1, constant: 10)
answerTextViewBottom = NSLayoutConstraint(item: contentView, attribute: .bottom, relatedBy: .equal, toItem: answerTextView, attribute: .bottom, multiplier: 1, constant: 0)
let indicatorWidth = NSLayoutConstraint(item: indicatorImageView, attribute: .width, relatedBy: .equal, toItem: nil, attribute: .notAnAttribute, multiplier: 1, constant: 30)
let indicatorHeight = NSLayoutConstraint(item: indicatorImageView, attribute: .height, relatedBy: .equal, toItem: nil, attribute: .notAnAttribute, multiplier: 1, constant: 30)
let containerTrailing = NSLayoutConstraint(item: containerView, attribute: .trailing, relatedBy: .equal, toItem: contentView, attribute: .trailingMargin, multiplier: 1, constant: 5)
let containerWidth = NSLayoutConstraint(item: containerView, attribute: .width, relatedBy: .equal, toItem: nil, attribute: .notAnAttribute, multiplier: 1, constant: 30)
let containerTop = NSLayoutConstraint(item: containerView, attribute: .top, relatedBy: .equal, toItem: contentView,attribute: .top, multiplier: 1, constant: 10)
let containerHeight = NSLayoutConstraint(item: containerView, attribute: .height, relatedBy: .equal, toItem: questionLabel, attribute: .height, multiplier: 1, constant: 0)
NSLayoutConstraint.activate([questionLabelTop
, answerTextViewTop ,answerTextViewBottom, indicatorWidth, indicatorHeight, containerTrailing, containerTop, containerWidth, containerHeight])
}
private func addConstraintsDependOnPositionType(position:Position){
var questionLabelTrailing = NSLayoutConstraint()
var questionLabelLeading = NSLayoutConstraint()
var answerTextViewTrailing = NSLayoutConstraint()
var answerTextViewLeading = NSLayoutConstraint()
var indicatorFirstConstraint = NSLayoutConstraint()
var indicatorSecondConstraint = NSLayoutConstraint()
switch position {
case .left:
questionLabelTrailing = NSLayoutConstraint(item: questionLabel, attribute: .trailing, relatedBy: .equal, toItem: contentView, attribute: .trailingMargin, multiplier: 1, constant: -30)
questionLabelLeading = NSLayoutConstraint(item: questionLabel, attribute: .leading, relatedBy: .equal, toItem: contentView, attribute: .leadingMargin, multiplier: 1, constant: 0)
answerTextViewTrailing = NSLayoutConstraint(item: answerTextView, attribute: .trailing, relatedBy: .equal, toItem: contentView, attribute: .trailingMargin, multiplier: 1, constant: -30)
answerTextViewLeading = NSLayoutConstraint(item: answerTextView, attribute: .leading, relatedBy: .equal, toItem: contentView, attribute: .leadingMargin, multiplier: 1, constant: -5)
indicatorFirstConstraint = NSLayoutConstraint(item: indicatorImageView, attribute: .centerX, relatedBy: .equal, toItem: containerView, attribute: .centerX, multiplier: 1, constant: 0)
indicatorSecondConstraint = NSLayoutConstraint(item: indicatorImageView, attribute: .centerY, relatedBy: .equal, toItem: containerView, attribute: .centerY, multiplier: 1, constant: 0)
case .right:
questionLabelTrailing = NSLayoutConstraint(item: questionLabel, attribute: .trailing, relatedBy: .equal, toItem: contentView, attribute: .trailingMargin, multiplier: 1, constant: 0)
questionLabelLeading = NSLayoutConstraint(item: questionLabel, attribute: .leading, relatedBy: .equal, toItem: contentView, attribute: .leadingMargin, multiplier: 1, constant: 0)
answerTextViewTrailing = NSLayoutConstraint(item: answerTextView, attribute: .trailing, relatedBy: .equal, toItem: contentView, attribute: .trailingMargin, multiplier: 1, constant: 5)
answerTextViewLeading = NSLayoutConstraint(item: answerTextView, attribute: .leading, relatedBy: .equal, toItem: contentView, attribute: .leadingMargin, multiplier: 1, constant: 0)
indicatorFirstConstraint = NSLayoutConstraint(item: indicatorImageView, attribute: .leading, relatedBy: .equal, toItem: contentView, attribute: .leadingMargin, multiplier: 1, constant: -10)
indicatorSecondConstraint = NSLayoutConstraint(item: indicatorImageView, attribute: .top, relatedBy: .equal, toItem: contentView,attribute: .top, multiplier: 1, constant: 5)
}; NSLayoutConstraint.activate([questionLabelTrailing,questionLabelLeading,answerTextViewTrailing,answerTextViewLeading,indicatorFirstConstraint,indicatorSecondConstraint])
}
@objc private func didTapQuestion(_ recognizer: UIGestureRecognizer) {
self.didSelectQuestion?(self)
}
private func expand(withAnswer answer: String, animated: Bool) {
answerTextView.text = answer
expand(animated: animated)
}
private func expand(withAttributedAnswer attributedAnswer: NSAttributedString, animated: Bool) {
answerTextView.attributedText = attributedAnswer
expand(animated: animated)
}
private func expand(animated: Bool) {
answerTextView.isHidden = false
if animated {
answerTextView.alpha = 0
UIView.animate(withDuration: 0.5, animations: {
self.answerTextView.alpha = 1
})
}
answerTextViewBottom.constant = 15
update(arrow: .up, animated: animated)
}
private func collapse(animated: Bool) {
answerTextView.text = ""
answerTextView.isHidden = true
answerTextViewBottom.constant = -20
update(arrow: .down, animated: animated)
}
private func update(arrow: Arrow, animated: Bool) {
switch arrow {
case .up:
if animated {
// Change direction from down to up with animation
self.indicatorImageView.rotate(withAngle: CGFloat(0), animated: false)
self.indicatorImageView.rotate(withAngle: CGFloat(Double.pi), animated: true)
} else {
// Change direction from down to up without animation
self.indicatorImageView.rotate(withAngle: CGFloat(Double.pi), animated: false)
}
case .down:
if animated {
// Change direction from up to down with animation
self.indicatorImageView.rotate(withAngle: CGFloat(Double.pi), animated: false)
self.indicatorImageView.rotate(withAngle: CGFloat(0), animated: true)
} else {
// Change direction from up to down without animation
self.indicatorImageView.rotate(withAngle: CGFloat(0), animated: false)
}
}
}
}
enum Arrow: String {
case up
case down
}
public enum Position: String {
case left
case right
}
enum CellOperation {
case collapsed
case expand
case expanded
case collapse
}
extension UIImageView {
func rotate(withAngle angle: CGFloat, animated: Bool) {
UIView.animate(withDuration: animated ? 0.5 : 0, animations: {
self.transform = CGAffineTransform(rotationAngle: angle)
})
}
}