Browse Source

add progressView

pull/1/head
InKwon James Kim 5 years ago
parent
commit
8cd9061ba3
  1. 37
      GMERemittance/Extension/UIViewControllerExtension.swift

37
GMERemittance/Extension/UIViewControllerExtension.swift

@ -276,32 +276,53 @@ extension UIViewController {
} }
} }
private var associatedObjectHandle: UInt8 = 0
extension UIViewController { 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) { 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)") print("progress: \(percent)")
UIViewController.progressView.backgroundColor = AppConstants.themeRedColor
progressSubView.backgroundColor = AppConstants.themeRedColor
let width = view.frame.width * percent let width = view.frame.width * percent
UIView.animate( UIView.animate(
withDuration: 0.5, withDuration: 0.5,
animations: { 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 completion: { _ in
if width == self.view.frame.width { if width == self.view.frame.width {
UIView.animate( UIView.animate(
withDuration: 0.2, withDuration: 0.2,
animations: { animations: {
UIViewController.progressView.alpha = 0.0
progressSubView.alpha = 0.0
}, },
completion: { _ in 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
}) })
} }
} }

Loading…
Cancel
Save