增加进度显示

This commit is contained in:
xaoxuu 2020-06-22 16:34:21 +08:00
parent 24469b8d62
commit 232a04f293
7 changed files with 155 additions and 17 deletions

View File

@ -25,7 +25,8 @@ class TestAlertVC: BaseListVC {
"极端场景:短时间内调用了多次同一个弹窗", "极端场景:短时间内调用了多次同一个弹窗",
"极端场景:多个不同的弹窗重叠", "极端场景:多个不同的弹窗重叠",
"测试较长的标题和内容", "测试较长的标题和内容",
"测试特别长的标题和内容"] "测试特别长的标题和内容",
"场景:正在同步(更新进度)"]
} }
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
@ -188,6 +189,38 @@ class TestAlertVC: BaseListVC {
vm.add(action: .default, title: "我知道了", handler: nil) vm.add(action: .default, title: "我知道了", handler: nil)
} }
} }
} else if row == 8 {
Alert.push("progress") { (a) in
a.update { (vm) in
vm.scene = .loading
vm.title = "正在同步"
vm.message = "请稍等片刻"
}
a.startRotate()
a.update(progress: 0)
let s = DispatchSemaphore(value: 1)
DispatchQueue.global().async {
for i in 0 ... 5 {
s.wait()
DispatchQueue.main.async {
Alert.find("progress", last: { (a) in
a.update(progress: CGFloat(i)/5)
print("\(CGFloat(i)/5)")
if i == 5 {
a.update { (vm) in
vm.scene = .success
vm.title = "同步成功"
vm.message = nil
}
}
})
DispatchQueue.main.asyncAfter(deadline: .now()+1) {
s.signal()
}
}
}
}
}
} }
} }

View File

@ -19,6 +19,7 @@ class TestToastVC: BaseListVC {
override var titles: [String] { override var titles: [String] {
return ["场景:正在同步", return ["场景:正在同步",
"场景:正在同步(更新进度)",
"场景:同步成功", "场景:同步成功",
"场景:同步失败", "场景:同步失败",
"场景:设备电量过低", "场景:设备电量过低",
@ -43,12 +44,44 @@ class TestToastVC: BaseListVC {
}.startRotate() }.startRotate()
simulateSync() simulateSync()
} else if row == 1 { } else if row == 1 {
Toast.push("progress") { (t) in
t.update { (vm) in
vm.scene = .loading
vm.title = "正在同步"
vm.message = "请稍等片刻"
}
t.startRotate()
t.update(progress: 0)
let s = DispatchSemaphore(value: 1)
DispatchQueue.global().async {
for i in 0 ... 5 {
s.wait()
DispatchQueue.main.async {
Toast.find("progress", last: { (t) in
t.update(progress: CGFloat(i)/5)
print("\(CGFloat(i)/5)")
if i == 5 {
t.update { (vm) in
vm.scene = .success
vm.title = "同步成功"
vm.message = "xxx"
}
}
})
DispatchQueue.main.asyncAfter(deadline: .now()+1) {
s.signal()
}
}
}
}
}
} else if row == 2 {
let t = Toast.push(scene: .success, title: "同步成功", message: "点击查看详情") let t = Toast.push(scene: .success, title: "同步成功", message: "点击查看详情")
t.didTapped { [weak self, weak t] in t.didTapped { [weak self, weak t] in
self?.presentEmptyVC(title: "详情") self?.presentEmptyVC(title: "详情")
t?.pop() t?.pop()
} }
} else if row == 2 { } else if row == 3 {
Toast.push(scene: .error, title: "同步失败", message: "请稍后重试。点击查看详情") { (vc) in Toast.push(scene: .error, title: "同步失败", message: "请稍后重试。点击查看详情") { (vc) in
vc.update { (vm) in vc.update { (vm) in
vm.duration = 0 vm.duration = 0
@ -58,10 +91,10 @@ class TestToastVC: BaseListVC {
vc?.pop() vc?.pop()
} }
} }
} else if row == 3 { } else if row == 4 {
Toast.push(scene: .warning, title: "设备电量过低", message: "请及时对设备进行充电,以免影响使用。") Toast.push(scene: .warning, title: "设备电量过低", message: "请及时对设备进行充电,以免影响使用。")
} else if row == 4 { } else if row == 5 {
Toast.push(scene: .default, title: "传入指定图标测试", message: "这是消息内容") { (vc) in Toast.push(scene: .default, title: "传入指定图标测试", message: "这是消息内容") { (vc) in
vc.update { (vm) in vc.update { (vm) in
if #available(iOS 13.0, *) { if #available(iOS 13.0, *) {
@ -72,14 +105,14 @@ class TestToastVC: BaseListVC {
} }
} }
} }
} else if row == 5 { } else if row == 6 {
Toast.push(scene: .default, title: "禁止手势移除", message: "这条消息无法通过向上滑动移出屏幕。5秒后自动消失每次拖拽都会刷新倒计时。") { (vc) in Toast.push(scene: .default, title: "禁止手势移除", message: "这条消息无法通过向上滑动移出屏幕。5秒后自动消失每次拖拽都会刷新倒计时。") { (vc) in
vc.isRemovable = false vc.isRemovable = false
vc.update { (vm) in vc.update { (vm) in
vm.duration = 5 vm.duration = 5
} }
} }
} else if row == 6 { } else if row == 7 {
Toast.push(scene: .message, title: "好友邀请", message: "你收到一条好友邀请,点击查看详情。", duration: 10) { (vc) in Toast.push(scene: .message, title: "好友邀请", message: "你收到一条好友邀请,点击查看详情。", duration: 10) { (vc) in
vc.identifier = "xxx" vc.identifier = "xxx"
vc.didTapped { [weak vc] in vc.didTapped { [weak vc] in
@ -97,7 +130,7 @@ class TestToastVC: BaseListVC {
} }
} }
} }
} else if row == 7 { } else if row == 8 {
if let t = Toast.find("aaa").last { if let t = Toast.find("aaa").last {
t.pulse() t.pulse()
t.update() { (vm) in t.update() { (vm) in
@ -112,7 +145,7 @@ class TestToastVC: BaseListVC {
} }
} }
} }
} else if row == 8 { } else if row == 9 {
Toast.push("aaa") { (t) in Toast.push("aaa") { (t) in
t.update { (vm) in t.update { (vm) in
vm.scene = .success vm.scene = .success
@ -121,7 +154,7 @@ class TestToastVC: BaseListVC {
} }
t.pulse() t.pulse()
} }
} else if row == 9 { } else if row == 10 {
Toast.push() { (a) in Toast.push() { (a) in
a.update { (vm) in a.update { (vm) in
vm.title = "正在同步看到了你撒地方快乐撒的肌肤轮廓啊就是;来的跨省的人格人格离开那地方离开过" vm.title = "正在同步看到了你撒地方快乐撒的肌肤轮廓啊就是;来的跨省的人格人格离开那地方离开过"
@ -129,7 +162,7 @@ class TestToastVC: BaseListVC {
} }
} }
} else if row == 10 { } else if row == 11 {
Toast.push() { (a) in Toast.push() { (a) in
a.update { (vm) in a.update { (vm) in
vm.title = "正在同步看到了你撒地方快乐撒的肌肤轮廓啊就是;来的跨省的人格人格离开那地方离开过正在同步看到了你撒地方快乐撒的肌肤轮廓啊就是;来的跨省的人格人格离开那地方离开过正在同步看到了你撒地方快乐撒的肌肤轮廓啊就是;来的跨省的人格人格离开那地方离开过" vm.title = "正在同步看到了你撒地方快乐撒的肌肤轮廓啊就是;来的跨省的人格人格离开那地方离开过正在同步看到了你撒地方快乐撒的肌肤轮廓啊就是;来的跨省的人格人格离开那地方离开过正在同步看到了你撒地方快乐撒的肌肤轮廓啊就是;来的跨省的人格人格离开那地方离开过"
@ -137,7 +170,7 @@ class TestToastVC: BaseListVC {
} }
} }
} else if row == 11 { } else if row == 12 {
Toast.push() { (a) in Toast.push() { (a) in
a.update { (vm) in a.update { (vm) in
vm.scene = .warning vm.scene = .warning
@ -145,7 +178,7 @@ class TestToastVC: BaseListVC {
} }
} }
} else if row == 12 { } else if row == 13 {
Toast.push() { (a) in Toast.push() { (a) in
a.update { (vm) in a.update { (vm) in
vm.scene = .warning vm.scene = .warning
@ -153,7 +186,7 @@ class TestToastVC: BaseListVC {
} }
} }
} else if row == 13 { } else if row == 14 {
Toast.push(scene: .privacy, title: "正在授权", message: "请稍等片刻") { (t) in Toast.push(scene: .privacy, title: "正在授权", message: "请稍等片刻") { (t) in
t.identifier = "loading" t.identifier = "loading"

View File

@ -6,7 +6,7 @@
"repositoryURL": "https://github.com/xaoxuu/Inspire", "repositoryURL": "https://github.com/xaoxuu/Inspire",
"state": { "state": {
"branch": "master", "branch": "master",
"revision": "cad0c64e6995a06ee3bf3ed7c632ad27c1b8ffb1", "revision": "43b6a9b7ebcd9f628590eac56cd88a85380dee21",
"version": null "version": null
} }
}, },
@ -15,7 +15,7 @@
"repositoryURL": "https://github.com/xaoxuu/ProHUD", "repositoryURL": "https://github.com/xaoxuu/ProHUD",
"state": { "state": {
"branch": "master", "branch": "master",
"revision": "d32d6f2dbec8d9464ead83be619d5c21fdb2a464", "revision": "58d752efc0ad1a2a49a46bc4106e318afe7a9f25",
"version": null "version": null
} }
}, },

View File

@ -129,6 +129,7 @@ fileprivate var privUpdateImage: (ProHUD.Alert) -> Void = {
vc.imageView.layer.removeAllAnimations() vc.imageView.layer.removeAllAnimations()
vc.animateLayer = nil vc.animateLayer = nil
vc.animation = nil vc.animation = nil
vc.progressView?.removeFromSuperview()
} }
}() }()

View File

@ -19,9 +19,11 @@ public class HUDController: UIViewController {
internal var didDisappearCallback: (() -> Void)? internal var didDisappearCallback: (() -> Void)?
/// ///
var animateLayer: CALayer? internal var animateLayer: CALayer?
internal var animation: CAAnimation? internal var animation: CAAnimation?
internal var progressView: ProHUD.ProgressView?
/// ///
internal var buttonEvents = [UIButton:() -> Void]() internal var buttonEvents = [UIButton:() -> Void]()
@ -96,7 +98,28 @@ internal extension HUDController {
public protocol LoadingAnimationView: HUDController { public protocol LoadingAnimationView: HUDController {
var imageView: UIImageView { get } var imageView: UIImageView { get }
} }
public extension LoadingAnimationView {
/// updateProgress(0)
/// - Parameter progress: 0~1
func update(progress: CGFloat) {
if let spv = imageView.superview {
if progressView == nil {
let v = ProHUD.ProgressView()
spv.addSubview(v)
v.snp.makeConstraints { (mk) in
mk.center.equalTo(imageView)
mk.width.height.equalTo(28)
}
progressView = v
}
if let v = progressView {
v.updateProgress(progress: progress)
}
}
}
}
/// ///
public protocol LoadingRotateAnimation: LoadingAnimationView {} public protocol LoadingRotateAnimation: LoadingAnimationView {}
public extension LoadingRotateAnimation { public extension LoadingRotateAnimation {

View File

@ -38,6 +38,52 @@ public extension ProHUD {
case counterclockwise = -1 case counterclockwise = -1
} }
///
class ProgressView: UIView {
var progressLayer = CAShapeLayer()
override init(frame: CGRect) {
//
let maxSize = CGFloat(28)
super.init(frame: .init(x: 0, y: 0, width: maxSize, height: maxSize))
layer.cornerRadius = maxSize / 2
layer.masksToBounds = true
//
let radius = maxSize / 2 - 4
backgroundColor = .white
let path = UIBezierPath(arcCenter: CGPoint(x: 14, y: 14), radius: radius/2, startAngle: -CGFloat.pi*0.5, endAngle: CGFloat.pi * 1.5, clockwise: true)
progressLayer.fillColor = UIColor.clear.cgColor
progressLayer.path = path.cgPath
progressLayer.strokeColor = tintColor.cgColor
progressLayer.lineWidth = radius
progressLayer.strokeStart = 0
progressLayer.strokeEnd = 0
layer.addSublayer(progressLayer)
}
required init(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
func updateProgress(progress: CGFloat) {
if progress <= 1 {
//
if progressLayer.superlayer == nil {
progressLayer.strokeEnd = 0
layer.addSublayer(progressLayer)
}
progressLayer.strokeEnd = progress
}
}
}
} }
// MARK: - internal // MARK: - internal

View File

@ -116,6 +116,8 @@ fileprivate var privReloadData: (ProHUD.Toast) -> Void = {
// //
vc.vm.updateDuration() vc.vm.updateDuration()
vc.progressView?.removeFromSuperview()
} }
}() }()