This repository was archived by the owner on Nov 3, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 631
Expand file tree
/
Copy pathTransientAlertViewController.swift
More file actions
73 lines (59 loc) · 1.68 KB
/
TransientAlertViewController.swift
File metadata and controls
73 lines (59 loc) · 1.68 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
//
// TransientAlertViewController.swift
// PanModal
//
// Created by Stephen Sowole on 3/1/19.
// Copyright © 2019 Detail. All rights reserved.
//
import UIKit
class TransientAlertViewController: AlertViewController {
private weak var timer: Timer?
private var countdown: Int = 5
override func viewDidLoad() {
super.viewDidLoad()
alertView.titleLabel.text = "Transient Alert"
updateMessage()
}
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
startTimer()
}
private func startTimer() {
timer?.invalidate()
if #available(iOS 10.0, *) {
timer = Timer.scheduledTimer(withTimeInterval: 1.0, repeats: true) { [weak self] _ in
self?.updateMessage()
}
} else {
Timer.scheduledTimer(timeInterval: 1.0, target: self, selector: #selector(self.updateMessage), userInfo: nil, repeats: true)
}
}
@objc func updateMessage() {
countdown -= 1
guard countdown > 0 else {
invalidateTimer()
dismiss(animated: true, completion: nil)
return
}
alertView.message.text = "Message disppears in \(countdown) seconds"
}
func invalidateTimer() {
timer?.invalidate()
}
deinit {
invalidateTimer()
}
// MARK: - Pan Modal Presentable
override var showDragIndicator: Bool {
return false
}
override var anchorModalToLongForm: Bool {
return true
}
override var panModalBackgroundColor: UIColor {
return .clear
}
override var isUserInteractionEnabled: Bool {
return false
}
}