2019-07-31 17:40:39 +08:00
|
|
|
//
|
|
|
|
// HUDView.swift
|
|
|
|
// ProHUD
|
|
|
|
//
|
|
|
|
// Created by xaoxuu on 2019/7/29.
|
|
|
|
// Copyright © 2019 Titan Studio. All rights reserved.
|
|
|
|
//
|
|
|
|
|
|
|
|
import UIKit
|
|
|
|
|
|
|
|
public extension ProHUD {
|
|
|
|
|
2019-08-01 20:22:57 +08:00
|
|
|
class ToastWindow: UIWindow {
|
|
|
|
|
|
|
|
var deviceOrientationDidChangeCallback: (() -> Void)?
|
|
|
|
|
|
|
|
public override init(frame: CGRect) {
|
|
|
|
super.init(frame: frame)
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
required init?(coder: NSCoder) {
|
|
|
|
fatalError("init(coder:) has not been implemented")
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@objc func deviceOrientationDidChange(_ notification: Notification){
|
|
|
|
DispatchQueue.main.asyncAfter(deadline: .now()+0.5) {
|
|
|
|
self.deviceOrientationDidChangeCallback?()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2019-07-31 17:40:39 +08:00
|
|
|
class StackContainer: UIStackView {
|
|
|
|
|
|
|
|
|
|
|
|
public override init(frame: CGRect) {
|
|
|
|
super.init(frame: frame)
|
2019-07-31 21:08:25 +08:00
|
|
|
spacing = alertConfig.margin
|
2019-07-31 17:40:39 +08:00
|
|
|
distribution = .fill
|
|
|
|
alignment = .center
|
|
|
|
axis = .vertical
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
required init(coder: NSCoder) {
|
|
|
|
fatalError("init(coder:) has not been implemented")
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
class BlurView: UIVisualEffectView {
|
|
|
|
|
|
|
|
|
|
|
|
init() {
|
2019-08-03 16:22:50 +08:00
|
|
|
|
|
|
|
if #available(iOS 13.0, *) {
|
|
|
|
super.init(effect: UIBlurEffect(style: .systemMaterial))
|
|
|
|
// backgroundColor = UIColor.init(white: 1, alpha: 0.3)
|
|
|
|
} else {
|
|
|
|
super.init(effect: UIBlurEffect(style: .extraLight))
|
|
|
|
backgroundColor = UIColor.init(white: 1, alpha: 0.66)
|
|
|
|
}
|
|
|
|
|
2019-07-31 17:40:39 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
required init?(coder: NSCoder) {
|
|
|
|
fatalError("init(coder:) has not been implemented")
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
internal extension UIView {
|
|
|
|
|
|
|
|
class func animateEaseOut(duration: TimeInterval = 1, delay: TimeInterval = 0, animations: @escaping () -> Void, completion: ((Bool) -> Void)? = nil) {
|
|
|
|
animate(withDuration: duration, delay: delay, usingSpringWithDamping: 1, initialSpringVelocity: 1, options: [.allowUserInteraction, .curveEaseOut], animations: animations, completion: completion)
|
|
|
|
}
|
|
|
|
|
2019-08-02 13:55:23 +08:00
|
|
|
class func animateForAlertBuildIn(animations: @escaping () -> Void) {
|
|
|
|
animateEaseOut(duration: 0.8, delay: 0, animations: animations, completion: nil)
|
|
|
|
}
|
|
|
|
class func animateForAlertBuildOut(animations: @escaping () -> Void, completion: ((Bool) -> Void)? = nil) {
|
|
|
|
animateEaseOut(duration: 0.38, delay: 0, animations: animations, completion: completion)
|
|
|
|
}
|
|
|
|
class func animateForAlert(animations: @escaping () -> Void) {
|
|
|
|
animateEaseOut(duration: 1, delay: 0, animations: animations, completion: nil)
|
2019-07-31 17:40:39 +08:00
|
|
|
}
|
|
|
|
|
2019-08-02 13:55:23 +08:00
|
|
|
class func animateForAlert(animations: @escaping () -> Void, completion: ((Bool) -> Void)? = nil) {
|
|
|
|
animateEaseOut(duration: 1, delay: 0, animations: animations, completion: completion)
|
2019-07-31 17:40:39 +08:00
|
|
|
}
|
|
|
|
|
2019-07-31 21:08:25 +08:00
|
|
|
class func animateForToast(animations: @escaping () -> Void) {
|
|
|
|
animateEaseOut(duration: 1, delay: 0, animations: animations, completion: nil)
|
|
|
|
}
|
|
|
|
|
|
|
|
class func animateForToast(animations: @escaping () -> Void, completion: ((Bool) -> Void)? = nil) {
|
|
|
|
animateEaseOut(duration: 1, delay: 0, animations: animations, completion: completion)
|
|
|
|
}
|
|
|
|
|
2019-08-03 16:22:50 +08:00
|
|
|
class func animateForGuard(animations: @escaping () -> Void) {
|
|
|
|
animateForGuard(animations: animations, completion: nil)
|
|
|
|
}
|
|
|
|
|
|
|
|
class func animateForGuard(animations: @escaping () -> Void, completion: ((Bool) -> Void)? = nil) {
|
|
|
|
animateEaseOut(duration: 0.6, delay: 0, animations: animations, completion: completion)
|
|
|
|
}
|
2019-07-31 17:40:39 +08:00
|
|
|
}
|