2018-10-02 01:25:10 +00:00
|
|
|
//
|
|
|
|
// LoadingViewController.swift
|
|
|
|
// Tusker
|
|
|
|
//
|
|
|
|
// Created by Shadowfacts on 10/1/18.
|
|
|
|
// Copyright © 2018 Shadowfacts. All rights reserved.
|
|
|
|
//
|
|
|
|
|
|
|
|
import UIKit
|
|
|
|
|
|
|
|
// Based on John Sundell's example: https://www.swiftbysundell.com/posts/using-child-view-controllers-as-plugins-in-swift
|
|
|
|
class LoadingViewController: UIViewController {
|
|
|
|
|
|
|
|
private var activityIndicator: UIActivityIndicatorView!
|
|
|
|
|
|
|
|
override func viewDidLoad() {
|
|
|
|
super.viewDidLoad()
|
|
|
|
|
2020-01-26 03:09:00 +00:00
|
|
|
view.backgroundColor = .clear
|
2019-06-15 00:23:03 +00:00
|
|
|
|
2019-06-04 21:04:37 +00:00
|
|
|
activityIndicator = UIActivityIndicatorView(style: .large)
|
2019-06-15 00:23:03 +00:00
|
|
|
activityIndicator.color = .secondaryLabel
|
2018-10-02 01:25:10 +00:00
|
|
|
activityIndicator.translatesAutoresizingMaskIntoConstraints = false
|
|
|
|
|
|
|
|
view.addSubview(activityIndicator)
|
|
|
|
|
|
|
|
activityIndicator.centerXAnchor.constraint(equalTo: view.safeAreaLayoutGuide.centerXAnchor).isActive = true
|
|
|
|
activityIndicator.centerYAnchor.constraint(equalTo: view.safeAreaLayoutGuide.centerYAnchor).isActive = true
|
|
|
|
}
|
|
|
|
|
|
|
|
override func viewWillAppear(_ animated: Bool) {
|
|
|
|
super.viewWillAppear(animated)
|
|
|
|
|
|
|
|
// 0.5s delay so indicator is not shown if data loads very quickly
|
|
|
|
DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) { [weak self] in
|
|
|
|
self?.activityIndicator.startAnimating()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|