|
@@ -1,5 +1,5 @@
|
|
|
//
|
|
|
-// TSGeneratorloadingView.swift
|
|
|
+// TSGeneratorView.swift
|
|
|
// AIEmoji
|
|
|
//
|
|
|
// Created by 100Years on 2025/4/2.
|
|
@@ -7,77 +7,39 @@
|
|
|
|
|
|
import Kingfisher
|
|
|
|
|
|
-class TSGeneratorloadingView: TSBaseView {
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- lazy var generatorContentView: UIView = {
|
|
|
- let generatorContentView = UIView()
|
|
|
- generatorContentView.backgroundColor = .clear
|
|
|
- return generatorContentView
|
|
|
- }()
|
|
|
-
|
|
|
- lazy var failedImageView: UIImageView = {
|
|
|
- let imageView = UIImageView.createImageView(imageName: "failed_big")
|
|
|
- imageView.isHidden = true
|
|
|
- return imageView
|
|
|
- }()
|
|
|
-
|
|
|
- lazy var animatedImageView: AnimatedImageView = {
|
|
|
- let animatedImageView = AnimatedImageView()
|
|
|
- animatedImageView.autoPlayAnimatedImage = false
|
|
|
- if let gifURL = Bundle.main.url(forResource: "rotatingAnimation", withExtension: "gif") {
|
|
|
- animatedImageView.kf.setImage(with: gifURL, options: [.cacheOriginalImage]) { result in
|
|
|
- switch result {
|
|
|
- case .success(let value):
|
|
|
- print("GIF 加载成功: \(value.source.url?.absoluteString ?? "")")
|
|
|
- case .failure(let error):
|
|
|
- print("GIF 加载失败: \(error.localizedDescription)")
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- return animatedImageView
|
|
|
- }()
|
|
|
-
|
|
|
-
|
|
|
- lazy var generatorCusStackView: TSCustomStackView = {
|
|
|
- let generatorCusStackView = TSCustomStackView(axis: .vertical,spacing: 0)
|
|
|
- generatorCusStackView.scrollView.isScrollEnabled = false
|
|
|
- return generatorCusStackView
|
|
|
- }()
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+let kTextLeading = 24.0
|
|
|
+
|
|
|
+class TSGeneratorView: TSBaseView {
|
|
|
|
|
|
- lazy var timeLabel: UILabel = {
|
|
|
- let textLabel = UILabel.createLabel(font: .font(size: 18,weight: .semibold),textColor: .white,textAlignment: .center)
|
|
|
- return textLabel
|
|
|
- }()
|
|
|
+ enum Style {
|
|
|
+ case loading //loading
|
|
|
+ case generalError //通用错误
|
|
|
+ case sensitiveError //敏感类的错误
|
|
|
+ case netWorkError //网络错误
|
|
|
+ }
|
|
|
|
|
|
- lazy var textLabel: UILabel = {
|
|
|
- let textLabel = UILabel.createLabel(font: .font(size: 18),textColor: .white,textAlignment: .center,numberOfLines: 0)
|
|
|
- return textLabel
|
|
|
+ var style:Style = .generalError
|
|
|
+
|
|
|
+ lazy var animationView: TSGeneratoringAnimationView = {
|
|
|
+ let animationView = TSGeneratoringAnimationView()
|
|
|
+ return animationView
|
|
|
}()
|
|
|
|
|
|
- lazy var infoLabel: UILabel = {
|
|
|
- let textLabel = UILabel.createLabel(font: .font(size: 14),textColor: .white.withAlphaComponent(0.6),textAlignment: .center,numberOfLines: 0)
|
|
|
- return textLabel
|
|
|
+ lazy var errorView: TSGeneratorErrorView = {
|
|
|
+ let errorView = TSGeneratorErrorView()
|
|
|
+ errorView.isHidden = true
|
|
|
+ return errorView
|
|
|
}()
|
|
|
-
|
|
|
- private var targetView: UIView = UIView()
|
|
|
-
|
|
|
-// lazy var blurEffect: UIVisualEffectView = {
|
|
|
-// let blurEffect = createBlurEffectView(style: .dark)
|
|
|
-// blurEffect.alpha = 0.9
|
|
|
-// return blurEffect
|
|
|
-// }()
|
|
|
-
|
|
|
+
|
|
|
lazy var blurEffect: TSDynamicBlurView = {
|
|
|
return TSDynamicBlurView()
|
|
|
}()
|
|
|
|
|
|
-
|
|
|
lazy var regenerateBtn: UIButton = {
|
|
|
let regenerateBtn = UIButton.createButton(title: "Regenerate".localized,backgroundImage: kSubmitBtnNormalbg,font: .font(size: 12),titleColor: "#111111".uiColor,corner: 22)
|
|
|
-// regenerateBtn.contentEdgeInsets = UIEdgeInsets(top: 0, left: 28, bottom: 0, right:28)
|
|
|
regenerateBtn.isHidden = true
|
|
|
return regenerateBtn
|
|
|
}()
|
|
@@ -106,12 +68,16 @@ class TSGeneratorloadingView: TSBaseView {
|
|
|
make.edges.equalToSuperview()
|
|
|
}
|
|
|
|
|
|
- contentView.addSubview(generatorContentView)
|
|
|
- generatorContentView.snp.makeConstraints { make in
|
|
|
- make.edges.equalToSuperview()
|
|
|
+ contentView.addSubview(animationView)
|
|
|
+ animationView.snp.makeConstraints { make in
|
|
|
+ make.leading.trailing.centerY.equalToSuperview()
|
|
|
+ }
|
|
|
+
|
|
|
+ contentView.addSubview(errorView)
|
|
|
+ errorView.snp.makeConstraints { make in
|
|
|
+ make.leading.trailing.centerY.equalToSuperview()
|
|
|
}
|
|
|
|
|
|
- setUpGeneratorContentView()
|
|
|
|
|
|
//关闭按钮
|
|
|
contentView.addSubview(xBtn)
|
|
@@ -121,81 +87,8 @@ class TSGeneratorloadingView: TSBaseView {
|
|
|
make.width.equalTo(36)
|
|
|
make.height.equalTo(36)
|
|
|
}
|
|
|
-
|
|
|
- timeLabel.superview?.isHidden = true
|
|
|
- infoLabel.superview?.isHidden = true
|
|
|
- setBackgroundGenerateBtnHidden(true)
|
|
|
-
|
|
|
}
|
|
|
|
|
|
-
|
|
|
- func setUpGeneratorContentView(){
|
|
|
- let imageViewTop = 225
|
|
|
- generatorContentView.addSubview(imageView)
|
|
|
- imageView.snp.makeConstraints { make in
|
|
|
- make.width.height.equalTo(200.0)
|
|
|
- make.centerX.equalToSuperview()
|
|
|
- make.top.equalTo(imageViewTop)
|
|
|
- }
|
|
|
-
|
|
|
- generatorContentView.addSubview(animatedImageView)
|
|
|
- animatedImageView.snp.makeConstraints { make in
|
|
|
- make.width.height.equalTo(200.0)
|
|
|
- make.centerX.equalToSuperview()
|
|
|
- make.top.equalTo(imageViewTop)
|
|
|
- }
|
|
|
-
|
|
|
- generatorContentView.addSubview(generatorCusStackView)
|
|
|
- generatorCusStackView.snp.makeConstraints { make in
|
|
|
- make.top.equalTo(imageView.snp.bottom).offset(-20)
|
|
|
- make.leading.equalTo(0)
|
|
|
- make.trailing.equalTo(0)
|
|
|
- make.bottom.equalTo(0)
|
|
|
- }
|
|
|
-
|
|
|
- generatorCusStackView.addSubviewToStackWhiteBoard(timeLabel)
|
|
|
- timeLabel.snp.makeConstraints { make in
|
|
|
- make.top.equalTo(0)
|
|
|
- make.leading.equalTo(16)
|
|
|
- make.trailing.equalTo(-16)
|
|
|
- make.height.equalTo(27)
|
|
|
- make.bottom.equalTo(-17)
|
|
|
- }
|
|
|
-
|
|
|
- generatorCusStackView.addSubviewToStackWhiteBoard(textLabel)
|
|
|
- textLabel.snp.makeConstraints { make in
|
|
|
- make.top.equalTo(0)
|
|
|
- make.leading.equalTo(16)
|
|
|
- make.trailing.equalTo(-16)
|
|
|
- make.bottom.equalTo(-8)
|
|
|
- }
|
|
|
-
|
|
|
- generatorCusStackView.addSubviewToStackWhiteBoard(infoLabel)
|
|
|
- infoLabel.snp.makeConstraints { make in
|
|
|
- make.top.equalTo(0)
|
|
|
- make.leading.equalTo(16)
|
|
|
- make.trailing.equalTo(-16)
|
|
|
- make.bottom.equalTo(-20)
|
|
|
- }
|
|
|
-
|
|
|
- generatorCusStackView.addSubviewToStackWhiteBoard(backgroundGenerateBtn)
|
|
|
- backgroundGenerateBtn.snp.makeConstraints { make in
|
|
|
- make.top.equalTo(20)
|
|
|
- make.leading.equalTo(32)
|
|
|
- make.trailing.equalTo(-32)
|
|
|
- make.height.equalTo(48)
|
|
|
- make.bottom.equalTo(0)
|
|
|
- }
|
|
|
-
|
|
|
- generatorCusStackView.addSubviewToStackWhiteBoard(regenerateBtn)
|
|
|
- regenerateBtn.snp.makeConstraints { make in
|
|
|
- make.top.equalTo(20)
|
|
|
- make.centerX.equalToSuperview()
|
|
|
- make.height.equalTo(44)
|
|
|
- make.width.equalTo(126*kDesignScale)
|
|
|
- make.bottom.equalTo(0)
|
|
|
- }
|
|
|
- }
|
|
|
|
|
|
override func dealThings() {
|
|
|
// 监听应用生命周期事件
|
|
@@ -214,56 +107,41 @@ class TSGeneratorloadingView: TSBaseView {
|
|
|
)
|
|
|
}
|
|
|
|
|
|
-
|
|
|
lazy var isRotating = false{
|
|
|
didSet{
|
|
|
if isRotating == true{
|
|
|
- startRotating(view: imageView)
|
|
|
+ animationView.startAnimation()
|
|
|
}else{
|
|
|
- stopRotating(view: imageView)
|
|
|
+ animationView.stopAnimation()
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-
|
|
|
- /// 开始旋转
|
|
|
- func startRotating(view:UIView,duration: Double = 2.0) {
|
|
|
- kDelayMainShort {
|
|
|
- self.animatedImageView.startAnimating()
|
|
|
- }
|
|
|
+ @objc private func handleAppDidEnterBackground() {
|
|
|
+ animationView.stopAnimation()
|
|
|
}
|
|
|
|
|
|
- /// 停止旋转
|
|
|
- func stopRotating(view:UIView) {
|
|
|
- animatedImageView.stopAnimating()
|
|
|
+ @objc private func handleAppWillEnterForeground() {
|
|
|
+ isRotating = isRotating
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+
|
|
|
func showLoading(text:String){
|
|
|
- animatedImageView.isHidden = false
|
|
|
- imageView.isHidden = true
|
|
|
-
|
|
|
- textLabel.text = text
|
|
|
isRotating = true
|
|
|
+ animationView.isHidden = false
|
|
|
+ errorView.isHidden = true
|
|
|
+
|
|
|
+ animationView.textLabel.text = text
|
|
|
}
|
|
|
|
|
|
func showError(text:String){
|
|
|
- animatedImageView.isHidden = true
|
|
|
-
|
|
|
- imageView.isHidden = false
|
|
|
- imageView.image = UIImage(named: "failed_big")
|
|
|
-
|
|
|
- textLabel.text = text
|
|
|
isRotating = false
|
|
|
- }
|
|
|
-
|
|
|
- @objc private func handleAppDidEnterBackground() {
|
|
|
- stopRotating(view: targetView)
|
|
|
+ animationView.isHidden = true
|
|
|
+ errorView.isHidden = false
|
|
|
+ errorView.style = style
|
|
|
}
|
|
|
|
|
|
- @objc private func handleAppWillEnterForeground() {
|
|
|
- isRotating = isRotating
|
|
|
- }
|
|
|
-
|
|
|
func setBackgroundColor(color:UIColor){
|
|
|
blurEffect.removeFromSuperview()
|
|
|
contentView.backgroundColor = color
|
|
@@ -271,42 +149,24 @@ class TSGeneratorloadingView: TSBaseView {
|
|
|
}
|
|
|
|
|
|
|
|
|
-extension TSGeneratorloadingView{
|
|
|
+extension TSGeneratorView{
|
|
|
|
|
|
func updateShowProgress(text:String) {
|
|
|
isHidden = false
|
|
|
showLoading(text: text)
|
|
|
isRotating = true
|
|
|
-
|
|
|
- if timeLabel.text?.count ?? 0 > 0 {
|
|
|
- timeLabel.superview?.isHidden = false
|
|
|
- }
|
|
|
-
|
|
|
- if infoLabel.text?.count ?? 0 > 0 {
|
|
|
- infoLabel.superview?.isHidden = false
|
|
|
- }
|
|
|
}
|
|
|
|
|
|
func updateShowLoading(text:String){
|
|
|
isHidden = false
|
|
|
showLoading(text: text)
|
|
|
isRotating = true
|
|
|
-
|
|
|
- if timeLabel.text?.count ?? 0 > 0 {
|
|
|
- timeLabel.superview?.isHidden = false
|
|
|
- }
|
|
|
-
|
|
|
- if infoLabel.text?.count ?? 0 > 0 {
|
|
|
- infoLabel.superview?.isHidden = false
|
|
|
- }
|
|
|
}
|
|
|
|
|
|
func updateShowError(text:String?){
|
|
|
isHidden = false
|
|
|
showError(text: text ?? kGenerateFailed)
|
|
|
isRotating = false
|
|
|
- timeLabel.superview?.isHidden = true
|
|
|
- infoLabel.superview?.isHidden = true
|
|
|
setBackgroundGenerateBtnHidden(true)
|
|
|
}
|
|
|
|