Tusker/Tusker/Screens/Utilities/LoadingViewController.swift

41 lines
1.3 KiB
Swift

//
// 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()
view.backgroundColor = .systemBackground
activityIndicator = UIActivityIndicatorView(style: .large)
activityIndicator.color = .secondaryLabel
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()
}
}
}