ProHUD/Example-Old/Example/TestGuardVC.swift

131 lines
5.6 KiB
Swift
Raw Normal View History

2019-08-12 17:59:40 +08:00
//
// TestGuardVC.swift
// Example
//
// Created by xaoxuu on 2019/8/12.
// Copyright © 2019 Titan Studio. All rights reserved.
//
import UIKit
import ProHUD
import Inspire
class TestGuardVC: BaseListVC {
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
}
override var titles: [String] {
2020-06-15 15:11:44 +08:00
return ["场景:删除菜单", "场景:升级至专业版", "场景:隐私协议页面", "对比原生的ActionSheet", "对比原生Present效果"]
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 {
2019-08-12 20:20:07 +08:00
Guard.push() { (vc) in
vc.update { (vm) in
vm.add(action: .destructive, title: "删除") { [weak vc] in
Alert.push(scene: .delete, title: "确认删除", message: "此操作不可撤销") { (vc) in
vc.update { (vm) in
vm.add(action: .destructive, title: "删除") { [weak vc] in
vc?.pop()
}
vm.add(action: .cancel, title: "取消", handler: nil)
}
2019-08-12 17:59:40 +08:00
}
2019-08-12 20:20:07 +08:00
vc?.pop()
2019-08-12 17:59:40 +08:00
}
2019-08-12 20:20:07 +08:00
vm.add(action: .cancel, title: "取消", handler: nil)
2019-08-12 17:59:40 +08:00
}
}
} else if row == 1 {
// id
2019-08-12 20:20:07 +08:00
Guard.find("pro") {
Guard.push() { (vc) in
vc.identifier = "pro"
vc.update { (vm) in
vm.add(title: "升级至专业版")
vm.add(subTitle: "解锁功能")
vm.add(message: "功能1功能2...")
vm.add(subTitle: "价格")
vm.add(message: "只需一次性付费$2999即可永久享用。")
2020-06-15 15:11:44 +08:00
vm.add(message: "只需一次性付费$2999即可永久享用。")
2019-08-12 20:20:07 +08:00
vm.add(action: .destructive, title: "购买") { [weak vc] in
2019-08-13 11:32:27 +08:00
Alert.push(scene: .buy) { (vc) in
2019-08-12 20:20:07 +08:00
vc.identifier = "confirm"
vc.update { (vm) in
vm.add(action: .destructive, title: "购买") { [weak vc] in
vc?.update({ (vm) in
2019-08-13 11:32:27 +08:00
vm.scene = .loading
vm.title = "正在付款"
vm.message = "请稍等片刻"
vm.remove(action: 0, 1)
2019-08-12 20:20:07 +08:00
})
2019-08-13 11:32:27 +08:00
vc?.rotate()
DispatchQueue.main.asyncAfter(deadline: .now()+1) {
vc?.update({ (vm) in
vm.scene = .success
vm.title = "购买成功"
vm.message = "感谢您的支持"
vm.add(action: .default, title: "我知道了") {
vc?.pop()
}
})
}
2019-08-12 17:59:40 +08:00
}
2019-08-12 20:20:07 +08:00
vm.add(action: .cancel, title: "取消", handler: nil)
}
2019-08-12 17:59:40 +08:00
}
2019-08-12 20:20:07 +08:00
vc?.pop()
2019-08-12 17:59:40 +08:00
}
2019-08-12 20:20:07 +08:00
vm.add(action: .cancel, title: "取消", handler: nil)
2019-08-12 17:59:40 +08:00
}
}
}
} else if row == 2 {
2019-08-12 20:20:07 +08:00
Guard.push() { (vc) in
vc.isFullScreen = true
vc.update { (vm) in
let titleLabel = vm.add(title: "隐私协议")
titleLabel.snp.makeConstraints { (mk) in
mk.height.equalTo(44)
}
let tv = UITextView()
tv.backgroundColor = .white
tv.isEditable = false
vc.textStack.addArrangedSubview(tv)
tv.text = "这里可以插入一个webView"
vm.add(message: "请认真阅读以上内容,当您阅读完毕并同意协议内容时点击接受按钮。")
vm.add(action: .default, title: "接受") { [weak vc] in
vc?.pop()
}
2019-08-12 17:59:40 +08:00
}
}
2020-06-15 15:11:44 +08:00
} else if row == 3 {
let ac = UIAlertController(title: "Title", message: "message", preferredStyle: .actionSheet)
let ok = UIAlertAction(title: "OK", style: .default, handler: nil)
let cancel = UIAlertAction(title: "Cancel", style: .cancel, handler: nil)
ac.addAction(ok)
ac.addAction(cancel)
2020-06-16 16:50:53 +08:00
ac.popoverPresentationController?.sourceView = tableView.cellForRow(at: indexPath)
2020-06-15 15:11:44 +08:00
self.present(ac, animated: true, completion: nil)
} else if row == 4 {
let vc = UIViewController()
vc.view.backgroundColor = .white
vc.title = "ceshi"
2020-06-16 16:50:53 +08:00
2020-06-15 15:11:44 +08:00
present(vc, animated: true, completion: nil)
2019-08-12 17:59:40 +08:00
}
2020-06-15 15:11:44 +08:00
2019-08-12 17:59:40 +08:00
}
}