123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156 |
- //
- // Untitled.swift
- // AIEmoji
- //
- // Created by 100Years on 2025/5/12.
- //
- import Kingfisher
- class TSGeneratoringAnimationView : TSBaseView {
-
- var isShowBackGeneration:Bool = false {
- didSet{
- UIView.animate(withDuration: 0.3) {
- self.backgroundGenerateBtn.isHidden = !self.isShowBackGeneration
- }
- }
- }
-
- lazy var cusStackView: UIStackView = {
- let cusStackView = UIStackView()
- cusStackView.axis = .vertical
- cusStackView.distribution = .fill
- cusStackView.alignment = .center
- return cusStackView
- }()
-
- lazy var animatedImageView: AnimatedImageView = {
- let animatedImageView = AnimatedImageView()
- animatedImageView.autoPlayAnimatedImage = false
- if let gifURL = Bundle.main.url(forResource: "rotatingAnimation_1", 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 timeLabel: UILabel = {
- let textLabel = UILabel.createLabel(font: .font(size: 18,weight: .semibold),textColor: .white,textAlignment: .center)
- textLabel.isHidden = true
- return textLabel
- }()
-
- lazy var textLabel: UILabel = {
- let textLabel = UILabel.createLabel(font: .font(size: 18),textColor: .white,textAlignment: .center,numberOfLines: 0)
- textLabel.isHidden = true
- return textLabel
- }()
-
- lazy var infoLabel: UILabel = {
- let textLabel = UILabel.createLabel(font: .font(size: 14),textColor: .white.withAlphaComponent(0.6),textAlignment: .center,numberOfLines: 0)
- textLabel.isHidden = true
- return textLabel
- }()
-
- 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
- btn.isHidden = true
- return btn
- }()
-
-
- override func creatUI() {
-
- contentView.addSubview(cusStackView)
- cusStackView.snp.makeConstraints { make in
- make.edges.equalToSuperview()
- }
-
- setUpGeneratorContentView()
- }
-
- func setUpGeneratorContentView(){
-
- cusStackView.addArrangedSubview(animatedImageView)
- animatedImageView.snp.makeConstraints { make in
- make.top.equalTo(0)
- make.width.height.equalTo(120)
- }
-
- cusStackView.addSpacing(length: 12.0)
-
- cusStackView.addArrangedSubview(timeLabel)
- timeLabel.snp.makeConstraints { make in
- make.leading.equalTo(kTextLeading)
- make.trailing.equalTo(-kTextLeading)
- }
-
- cusStackView.addSpacing(length: 16.0)
-
- cusStackView.addArrangedSubview(textLabel)
- textLabel.snp.makeConstraints { make in
- make.leading.equalTo(kTextLeading)
- make.trailing.equalTo(-kTextLeading)
- }
-
- cusStackView.addSpacing(length: 8.0)
-
- cusStackView.addArrangedSubview(infoLabel)
- infoLabel.snp.makeConstraints { make in
- make.leading.equalTo(kTextLeading)
- make.trailing.equalTo(-kTextLeading)
- }
-
- cusStackView.addSpacing(length: 20.0)
-
- cusStackView.addArrangedSubview(backgroundGenerateBtn)
- backgroundGenerateBtn.snp.makeConstraints { make in
- make.width.lessThanOrEqualTo(k_ScreenWidth - 64)
- make.width.greaterThanOrEqualTo(250)
- make.height.equalTo(48)
- make.bottom.equalTo(0)
- }
- }
- }
- extension TSGeneratoringAnimationView {
-
-
- func startAnimation() {
- kDelayMainShort {
- self.animatedImageView.startAnimating()
- }
- }
- func stopAnimation() {
- self.animatedImageView.stopAnimating()
- }
-
- func setText(time:String,info:String) {
- timeLabel.text = time
- infoLabel.text = info
-
- timeLabel.isHidden = time.isEmpty
- infoLabel.isHidden = info.isEmpty
- }
-
- func setProgressText(text:String) {
- textLabel.text = text
- textLabel.isHidden = text.isEmpty
- }
- }
|