diff --git a/LinearProgressBarDemo/ViewController.swift b/LinearProgressBarDemo/ViewController.swift index 0115f0f..7510180 100644 --- a/LinearProgressBarDemo/ViewController.swift +++ b/LinearProgressBarDemo/ViewController.swift @@ -17,7 +17,8 @@ class ViewController: UIViewController { prepareNavigationController() - showProgressBar() + let view = showProgressBar(5) + } } diff --git a/Sources/LinearProgressBar.swift b/Sources/LinearProgressBar.swift index f1ad318..122af6f 100644 --- a/Sources/LinearProgressBar.swift +++ b/Sources/LinearProgressBar.swift @@ -108,6 +108,13 @@ open class LinearProgressBar: UIView { completion?() } + open func animateForAWhile(_ duration: TimeInterval) { + startAnimating() + DispatchQueue.main.asyncAfter(deadline: .now() + duration) { + self.stopAnimating() + } + } + // MARK: - Private private func applyProgressAnimations() { diff --git a/Sources/ProgressBar.swift b/Sources/ProgressBar.swift index 4b7aad0..57070b4 100644 --- a/Sources/ProgressBar.swift +++ b/Sources/ProgressBar.swift @@ -14,6 +14,11 @@ import UIKit return ProgressBar.showProgressBar(self.view) } + @discardableResult + func showProgressBar(_ duration: TimeInterval) -> UIView { + ProgressBar.showProgressBar(duration: duration, self.view) + } + func hideProgressBar() { ProgressBar.removeAllProgressBars(self.view) } @@ -79,4 +84,16 @@ open class ProgressBar: NSObject { } } } + + open class func showProgressBar(duration: TimeInterval,_ parentView: UIView) -> UIView { + let progressBar = LinearProgressBar() + progressBar.tag = progressBarViewTag + + parentView.addSubview(progressBar) + + Layout.toTop(progressBar) + progressBar.animateForAWhile(duration) + + return progressBar + } }