|
|
@ -276,32 +276,53 @@ extension UIViewController { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
private var associatedObjectHandle: UInt8 = 0 |
|
|
|
extension UIViewController { |
|
|
|
private static var progressView = UIView(frame: CGRect(x: 0, y: 0, width: 0, height: 2)) |
|
|
|
private var progressView: UIView? { |
|
|
|
get { |
|
|
|
guard let view = objc_getAssociatedObject(self, &associatedObjectHandle) as? UIView else { |
|
|
|
return nil |
|
|
|
} |
|
|
|
|
|
|
|
return view |
|
|
|
} |
|
|
|
set { |
|
|
|
objc_setAssociatedObject(self, &associatedObjectHandle, newValue, objc_AssociationPolicy.OBJC_ASSOCIATION_RETAIN_NONATOMIC) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
func setPercent(with percent: CGFloat) { |
|
|
|
UIViewController.progressView.removeFromSuperview() |
|
|
|
view.addSubview(UIViewController.progressView) |
|
|
|
let progressSubView: UIView |
|
|
|
|
|
|
|
if let view = progressView { |
|
|
|
progressSubView = view |
|
|
|
} else { |
|
|
|
progressSubView = UIView(frame: CGRect(x: 0, y: 0, width: 0, height: 2)) |
|
|
|
progressView = progressSubView |
|
|
|
} |
|
|
|
|
|
|
|
progressSubView.removeFromSuperview() |
|
|
|
view.addSubview(progressSubView) |
|
|
|
|
|
|
|
print("progress: \(percent)") |
|
|
|
UIViewController.progressView.backgroundColor = AppConstants.themeRedColor |
|
|
|
progressSubView.backgroundColor = AppConstants.themeRedColor |
|
|
|
let width = view.frame.width * percent |
|
|
|
|
|
|
|
UIView.animate( |
|
|
|
withDuration: 0.5, |
|
|
|
animations: { |
|
|
|
UIViewController.progressView.frame = CGRect(x: 0, y: 0, width: width, height: 2) |
|
|
|
progressSubView.frame = CGRect(x: 0, y: 0, width: width, height: 2) |
|
|
|
}, |
|
|
|
completion: { _ in |
|
|
|
if width == self.view.frame.width { |
|
|
|
UIView.animate( |
|
|
|
withDuration: 0.2, |
|
|
|
animations: { |
|
|
|
UIViewController.progressView.alpha = 0.0 |
|
|
|
progressSubView.alpha = 0.0 |
|
|
|
}, |
|
|
|
completion: { _ in |
|
|
|
UIViewController.progressView.frame = CGRect(x: 0, y: 0, width: 0, height: 2) |
|
|
|
UIViewController.progressView.alpha = 1.0 |
|
|
|
progressSubView.frame = CGRect(x: 0, y: 0, width: 0, height: 2) |
|
|
|
progressSubView.alpha = 1.0 |
|
|
|
}) |
|
|
|
} |
|
|
|
} |
|
|
|