|
@@ -0,0 +1,320 @@
|
|
|
+//
|
|
|
+// TSGeneratorloadingContentView.swift
|
|
|
+// AIEmoji
|
|
|
+//
|
|
|
+// Created by 100Years on 2025/5/12.
|
|
|
+//
|
|
|
+
|
|
|
+import Kingfisher
|
|
|
+
|
|
|
+class TSGeneratorloadingContentView: TSBaseView {
|
|
|
+ lazy var generatorContentView: UIView = {
|
|
|
+ let generatorContentView = UIView()
|
|
|
+ generatorContentView.backgroundColor = .clear
|
|
|
+ return generatorContentView
|
|
|
+ }()
|
|
|
+
|
|
|
+ lazy var imageView: 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
|
|
|
+ }()
|
|
|
+
|
|
|
+ lazy var timeLabel: UILabel = {
|
|
|
+ let textLabel = UILabel.createLabel(font: .font(size: 18,weight: .semibold),textColor: .white,textAlignment: .center)
|
|
|
+ return textLabel
|
|
|
+ }()
|
|
|
+
|
|
|
+ lazy var textLabel: UILabel = {
|
|
|
+ let textLabel = UILabel.createLabel(font: .font(size: 18),textColor: .white,textAlignment: .center,numberOfLines: 0)
|
|
|
+ return textLabel
|
|
|
+ }()
|
|
|
+
|
|
|
+ lazy var infoLabel: UILabel = {
|
|
|
+ let textLabel = UILabel.createLabel(font: .font(size: 14),textColor: .white.withAlphaComponent(0.6),textAlignment: .center,numberOfLines: 0)
|
|
|
+ return textLabel
|
|
|
+ }()
|
|
|
+
|
|
|
+ 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
|
|
|
+ }()
|
|
|
+
|
|
|
+ lazy var backgroundGenerateBtn: UIButton = {
|
|
|
+ let btn = UIButton.createButton(title: "Generate in the background".localized,font: .font(size: 16),titleColor: .themeColor,corner: 24)
|
|
|
+ btn.layer.borderColor = UIColor.themeColor.cgColor
|
|
|
+ btn.layer.borderWidth = 1.0
|
|
|
+ btn.titleLabel?.adjustsFontSizeToFitWidth = true
|
|
|
+ return btn
|
|
|
+ }()
|
|
|
+
|
|
|
+ lazy var xBtn: UIButton = {
|
|
|
+ let xBtn = UIButton.createButton(image: UIImage(named: "close_gray")) { [weak self] in
|
|
|
+ guard let self = self else { return }
|
|
|
+ self.isHidden = true
|
|
|
+ }
|
|
|
+ xBtn.isHidden = true
|
|
|
+ return xBtn
|
|
|
+ }()
|
|
|
+
|
|
|
+
|
|
|
+ override func creatUI() {
|
|
|
+ contentView.addSubview(blurEffect)
|
|
|
+ blurEffect.snp.makeConstraints { make in
|
|
|
+ make.edges.equalToSuperview()
|
|
|
+ }
|
|
|
+
|
|
|
+ contentView.addSubview(generatorContentView)
|
|
|
+ generatorContentView.snp.makeConstraints { make in
|
|
|
+ make.edges.equalToSuperview()
|
|
|
+ }
|
|
|
+
|
|
|
+ setUpGeneratorContentView()
|
|
|
+
|
|
|
+ //关闭按钮
|
|
|
+ contentView.addSubview(xBtn)
|
|
|
+ xBtn.snp.makeConstraints { make in
|
|
|
+ make.top.equalTo(k_Height_StatusBar + 4)
|
|
|
+ make.leading.equalTo(16)
|
|
|
+ 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() {
|
|
|
+ // 监听应用生命周期事件
|
|
|
+ NotificationCenter.default.addObserver(
|
|
|
+ self,
|
|
|
+ selector: #selector(handleAppDidEnterBackground),
|
|
|
+ name: UIApplication.didEnterBackgroundNotification,
|
|
|
+ object: nil
|
|
|
+ )
|
|
|
+
|
|
|
+ NotificationCenter.default.addObserver(
|
|
|
+ self,
|
|
|
+ selector: #selector(handleAppWillEnterForeground),
|
|
|
+ name: UIApplication.willEnterForegroundNotification,
|
|
|
+ object: nil
|
|
|
+ )
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ lazy var isRotating = false{
|
|
|
+ didSet{
|
|
|
+ if isRotating == true{
|
|
|
+ startRotating(view: imageView)
|
|
|
+ }else{
|
|
|
+ stopRotating(view: imageView)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /// 开始旋转
|
|
|
+ func startRotating(view:UIView,duration: Double = 2.0) {
|
|
|
+ kDelayMainShort {
|
|
|
+ self.animatedImageView.startAnimating()
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /// 停止旋转
|
|
|
+ func stopRotating(view:UIView) {
|
|
|
+ animatedImageView.stopAnimating()
|
|
|
+ }
|
|
|
+
|
|
|
+ func showLoading(text:String){
|
|
|
+ animatedImageView.isHidden = false
|
|
|
+ imageView.isHidden = true
|
|
|
+
|
|
|
+ textLabel.text = text
|
|
|
+ isRotating = true
|
|
|
+ }
|
|
|
+
|
|
|
+ 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)
|
|
|
+ }
|
|
|
+
|
|
|
+ @objc private func handleAppWillEnterForeground() {
|
|
|
+ isRotating = isRotating
|
|
|
+ }
|
|
|
+
|
|
|
+ func setBackgroundColor(color:UIColor){
|
|
|
+ blurEffect.removeFromSuperview()
|
|
|
+ contentView.backgroundColor = color
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+extension TSGeneratorloadingContentView{
|
|
|
+
|
|
|
+ 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)
|
|
|
+ }
|
|
|
+
|
|
|
+ func updateShowSuccess(){
|
|
|
+ isHidden = true
|
|
|
+ isRotating = false
|
|
|
+ setBackgroundGenerateBtnHidden(true)
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ func setBackgroundGenerateBtnHidden(_ isHidden:Bool){
|
|
|
+ backgroundGenerateBtn.superview?.isHidden = isHidden
|
|
|
+ }
|
|
|
+}
|