ProHUD/Example-Old/Example/TestAlertVC.swift

216 lines
8.9 KiB
Swift
Raw Normal View History

2019-08-12 17:59:40 +08:00
//
// TestAlertVC.swift
// Example
//
// Created by xaoxuu on 2019/8/12.
// Copyright © 2019 Titan Studio. All rights reserved.
//
import UIKit
import ProHUD
class TestAlertVC: BaseListVC {
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
}
override var titles: [String] {
2019-08-20 09:03:45 +08:00
return ["极端场景:正在同步(超时未处理)",
2019-08-13 11:32:27 +08:00
"场景同步成功写法1",
"场景同步成功写法2",
"场景:同步失败和重试",
2020-06-16 16:50:53 +08:00
"极端场景:短时间内调用了多次同一个弹窗",
"极端场景:多个不同的弹窗重叠",
"测试较长的标题和内容",
"测试特别长的标题和内容"]
2019-08-12 17:59:40 +08:00
}
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
tableView.deselectRow(at: indexPath, animated: true)
let row = indexPath.row
if row == 0 {
func f() {
2019-08-12 20:20:07 +08:00
Alert.push(scene: .loading, title: "正在同步", message: "请稍等片刻") { (a) in
a.identifier = "loading"
2019-08-13 11:32:27 +08:00
a.rotate()
2020-06-19 19:20:44 +08:00
a.didForceQuit {
2019-08-12 20:20:07 +08:00
let t = Toast.push(scene: .loading, title: "正在同步", message: "请稍等片刻点击展开为Alert") { (vm) in
vm.identifier = "loading"
}
2019-08-13 11:32:27 +08:00
t.rotate()
2019-08-12 20:20:07 +08:00
t.didTapped { [weak t] in
t?.pop()
f()
}
2019-08-12 17:59:40 +08:00
}
}
}
f()
} else if row == 1 {
2019-08-12 20:20:07 +08:00
Alert.push() { (a) in
a.identifier = "loading"
2019-08-13 11:32:27 +08:00
a.rotate()
2019-08-12 20:20:07 +08:00
a.update { (vm) in
vm.scene = .loading
vm.title = "正在同步"
vm.message = "请稍等片刻"
}
}
2019-08-12 17:59:40 +08:00
DispatchQueue.main.asyncAfter(deadline: .now()+2) {
2019-08-12 20:20:07 +08:00
Alert.find("loading", last: { (a) in
2019-08-12 17:59:40 +08:00
a.update { (vm) in
vm.scene = .success
vm.title = "同步成功"
vm.message = nil
}
2019-08-12 20:20:07 +08:00
})
2019-08-12 17:59:40 +08:00
}
} else if row == 2 {
2019-08-12 20:20:07 +08:00
let a = Alert.push() { (a) in
a.identifier = "loading"
}
2019-08-13 11:32:27 +08:00
a.rotate()
2019-08-12 20:20:07 +08:00
a.update { (vm) in
vm.scene = .loading
vm.title = "正在同步"
vm.message = "请稍等片刻"
}
DispatchQueue.main.asyncAfter(deadline: .now()+2) {
Alert.find("loading", last: { (a) in
a.update { (vm) in
vm.scene = .success
vm.title = "同步成功"
vm.message = nil
}
})
}
} else if row == 3 {
Alert.push() { (a) in
a.identifier = "loading"
2019-08-12 17:59:40 +08:00
}
func loading() {
2019-08-12 20:20:07 +08:00
Alert.find("loading", last: { (a) in
2019-08-12 17:59:40 +08:00
a.update { (vm) in
vm.scene = .loading
vm.title = "正在同步"
vm.message = "请稍等片刻"
vm.remove(action: 0, 1)
}
2019-08-13 11:32:27 +08:00
a.rotate()
2019-08-12 17:59:40 +08:00
DispatchQueue.main.asyncAfter(deadline: .now()+2) {
a.update { (vm) in
vm.scene = .error
vm.title = "同步失败"
vm.message = "请检查网络是否通畅"
vm.add(action: .default, title: "重试") {
loading()
}
vm.add(action: .cancel, title: "取消", handler: nil)
}
}
2019-08-12 20:20:07 +08:00
})
2019-08-12 17:59:40 +08:00
}
loading()
2019-08-13 11:32:27 +08:00
} else if row == 4 {
2020-06-16 16:50:53 +08:00
func loading(_ index: Int = 1) {
Alert.find("loading", last: { (a) in
Toast.find("loading-tip", last: { (t) in
t.update { (vm) in
vm.title = "此时又调用了一次相同的弹窗 x\(index)"
}
t.pulse()
}) {
Toast.push(title: "此时又调用了一次相同的弹窗 x\(index)", message: "页面应该是没有任何变化的") { (t) in
t.identifier = "loading-tip"
t.update { (vm) in
vm.scene = .default
}
}
}
}) {
Alert.push() { (a) in
a.identifier = "loading"
a.update { (vm) in
vm.scene = .loading
vm.title = "正在加载"
}
2020-06-16 17:33:46 +08:00
a.rotate()
2020-06-16 16:50:53 +08:00
}
}
}
loading(1)
DispatchQueue.main.asyncAfter(deadline: .now()+1) {
loading(2)
}
DispatchQueue.main.asyncAfter(deadline: .now()+2) {
loading(3)
}
DispatchQueue.main.asyncAfter(deadline: .now()+3) {
loading(4)
}
DispatchQueue.main.asyncAfter(deadline: .now()+3.5) {
loading(5)
}
DispatchQueue.main.asyncAfter(deadline: .now()+4) {
loading(6)
}
} else if row == 5 {
2019-08-13 11:32:27 +08:00
func f(_ i: Int) {
Alert.push() { (a) in
a.rotate()
a.update { (vm) in
vm.scene = .loading
vm.title = "正在同步" + String(i)
vm.message = "请稍等片刻"
}
}
}
f(1)
DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) {
f(2)
}
DispatchQueue.main.asyncAfter(deadline: .now() + 1) {
f(3)
}
DispatchQueue.main.asyncAfter(deadline: .now() + 2) {
f(4)
}
} else if row == 6 {
Alert.push() { (a) in
a.update { (vm) in
vm.scene = .confirm
vm.title = "正在同步看到了你撒地方快乐撒的肌肤轮廓啊就是;来的跨省的人格人格离开那地方离开过"
vm.message = "正在同步看到了你撒地方快乐撒的肌肤轮廓啊就是;来的跨省的人格人格离开那地方离开过正在同步看到了你撒地方快乐撒的肌肤轮廓啊就是;来的跨省的人格人格离开那地方离开过"
vm.add(action: .default, title: "我知道了", handler: nil)
}
}
} else if row == 7 {
Alert.push() { (a) in
a.update { (vm) in
vm.scene = .warning
vm.title = "正在同步看到了你撒地方快乐撒的肌肤轮廓啊就是;来的跨省的人格人格离开那地方离开过正在同步看到了你撒地方快乐撒的肌肤轮廓啊就是;来的跨省的人格人格离开那地方离开过正在同步看到了你撒地方快乐撒的肌肤轮廓啊就是;来的跨省的人格人格离开那地方离开过"
vm.message = "正在同步看到了你撒地方快乐撒的肌肤轮廓啊就是;来的跨省的人格人格离开那地方离开过正在同步看到了你撒地方快乐撒的肌肤轮廓啊就是;来的跨省的人格人格离开那地方离开过正在同步看到了你撒地方快乐撒的肌肤轮廓啊就是;来的跨省的人格人格离开那地方离开过正在同步看到了你撒地方快乐撒的肌肤轮廓啊就是;来的跨省的人格人格离开那地方离开过正在同步看到了你撒地方快乐撒的肌肤轮廓啊就是;来的跨省的人格人格离开那地方离开过正在同步看到了你撒地方快乐撒的肌肤轮廓啊就是;来的跨省的人格人格离开那地方离开过"
vm.add(action: .default, title: "我知道了", handler: nil)
}
}
2019-08-12 17:59:40 +08:00
}
}
func simulateSync() {
DispatchQueue.main.asyncAfter(deadline: .now() + 15) {
2019-08-12 20:20:07 +08:00
Alert.find("loading", last: { (a) in
a.update { (vm) in
2019-08-12 17:59:40 +08:00
vm.scene = .success
vm.title = "同步成功"
vm.message = "啊哈哈哈哈哈哈哈哈"
}
2019-08-12 20:20:07 +08:00
})
2019-08-12 17:59:40 +08:00
}
}
}