-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUIViewController+Extensions.swift
63 lines (51 loc) · 1.96 KB
/
UIViewController+Extensions.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
//
// UIViewController+Extensions.swift
// Swift Utilities
//
// Created by Tre`Von McKay on 11/10/16.
//
import Foundation
import UIKit
extension UIViewController{
func presentActivityIndicator() {
let delegate = UIApplication.shared.delegate as! AppDelegate
let screenSize = UIScreen.main.bounds
delegate.progressWindow = UIWindow(frame: screenSize)
delegate.progressWindow!.windowLevel = UIWindowLevelAlert
let overlayView = UIView(frame: screenSize)
overlayView.backgroundColor = UIColor.darkGray
overlayView.alpha = 0.6
let activityIndicator = UIActivityIndicatorView(activityIndicatorStyle: .whiteLarge)
activityIndicator.hidesWhenStopped = true
activityIndicator.center = overlayView.center
overlayView.addSubview(activityIndicator)
delegate.progressWindow!.addSubview(overlayView)
DispatchQueue.main.async {
delegate.progressWindow!.isHidden = false
activityIndicator.startAnimating()
}
}
func dismissActivityIndicator(){
let delegate = UIApplication.shared.delegate as! AppDelegate
DispatchQueue.main.async {
if delegate.progressWindow != nil{
delegate.progressWindow!.isHidden = true
}
}
}
func dismissKeyboardOnTap(_ selector: Selector) {
let tap: UITapGestureRecognizer = UITapGestureRecognizer(target: self, action: selector)
tap.cancelsTouchesInView = false
view.addGestureRecognizer(tap)
}
func traverseAndFindClass<T : UIViewController>() -> T? {
var currentViewController = self
while let parentViewController = currentViewController.parent {
if let result = parentViewController as? T {
return result
}
currentViewController = parentViewController
}
return nil
}
}