Tusker/Tusker/Screens/Utilities/LoadingViewController.swift

41 lines
1.3 KiB
Swift
Raw Normal View History

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()
2019-06-15 00:23:03 +00:00
view.backgroundColor = .systemBackground
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()
}
}
}