2019-07-31 17:40:39 +08:00
|
|
|
//
|
|
|
|
// HUDController.swift
|
|
|
|
// ProHUD
|
|
|
|
//
|
|
|
|
// Created by xaoxuu on 2019/7/29.
|
|
|
|
// Copyright © 2019 Titan Studio. All rights reserved.
|
|
|
|
//
|
|
|
|
|
|
|
|
import UIKit
|
|
|
|
|
|
|
|
public class HUDController: UIViewController {
|
|
|
|
|
2019-08-05 14:20:52 +08:00
|
|
|
/// ID标识
|
|
|
|
public var identifier = String(Date().timeIntervalSince1970)
|
2019-07-31 17:40:39 +08:00
|
|
|
|
|
|
|
/// 消失回调
|
|
|
|
internal var disappearCallback: (() -> Void)?
|
2019-08-05 14:20:52 +08:00
|
|
|
|
|
|
|
/// 按钮事件
|
2019-08-06 20:09:16 +08:00
|
|
|
fileprivate var buttonEvents = [UIButton:() -> Void]()
|
2019-07-31 17:40:39 +08:00
|
|
|
|
|
|
|
init() {
|
|
|
|
super.init(nibName: nil, bundle: nil)
|
2019-08-03 17:48:37 +08:00
|
|
|
debug(self, "init")
|
2019-07-31 17:40:39 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
required public init?(coder: NSCoder) {
|
|
|
|
fatalError("init(coder:) has not been implemented")
|
|
|
|
}
|
|
|
|
|
|
|
|
deinit {
|
2019-08-08 09:25:28 +08:00
|
|
|
debug("👌", self, "deinit")
|
2019-07-31 17:40:39 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
override public func viewDidLoad() {
|
|
|
|
super.viewDidLoad()
|
|
|
|
|
|
|
|
// Do any additional setup after loading the view.
|
|
|
|
}
|
|
|
|
|
2019-08-05 14:20:52 +08:00
|
|
|
public override func viewDidDisappear(_ animated: Bool) {
|
|
|
|
super.viewDidDisappear(animated)
|
|
|
|
disappearCallback?()
|
|
|
|
}
|
2019-07-31 17:40:39 +08:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
internal extension HUDController {
|
|
|
|
|
|
|
|
func addTouchUpAction(for button: UIButton, action: @escaping () -> Void) {
|
|
|
|
button.addTarget(self, action: #selector(didTappedButton(_:)), for: .touchUpInside)
|
|
|
|
buttonEvents[button] = action
|
|
|
|
}
|
|
|
|
|
|
|
|
@objc func didTappedButton(_ sender: UIButton) {
|
|
|
|
if let ac = buttonEvents[sender] {
|
|
|
|
ac()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|