SBWebImage 内置视图指示器加载动画不显示,SWIFT

SBWebImage build-in view indicator loading animation doesn't show, SWIFT

我正在尝试为图像在显示在视图上之前加载时获取加载动画。我正在使用 SDWebImage,我查看了他们在 GitHub 上的文档,并按照那里的指南进行了在线搜索,但它仍然没有显示任何加载动画。

我已经设置了 4 秒的延迟来查看动画是否被激活。

import UIKit
import Entities
import SDWebImage

public final class MediaView: View {
    private let imageView: UIImageView = {
        let this = UIImageView()
        this.translatesAutoresizingMaskIntoConstraints = false
        this.contentMode = .scaleAspectFit
        this.isHidden = true
        return this
    }()

    override public func configureView() {
    super.configureView()
    }

    override public func configureSubviews() {
        super.configureSubviews()
        addSubview(imageView)
    }

    override public func configureConstraints() {
        super.configureConstraints()
        imageView.edges(equalTo: self)
    }

    public func load(_ media: Media) {
        switch media {
        case .image(let imageData):
            
            imageView.sd_imageIndicator = SDWebImageActivityIndicator.gray <------ Loading animation here
            imageView.sd_imageIndicator = SDWebImageProgressIndicator.default <------ Loading animation here
            //imageView.sd_imageIndicator?.startAnimatingIndicator()
            
            DispatchQueue.main.asyncAfter(deadline: .now() + 4, execute: { [weak self] in
                self?.imageView.sd_setImage(with: imageData.url)
                self?.imageView.isHidden = false
            })
        case .unknown:
            break
        }
    }
}

你的 imageView 是隐藏的 this.isHidden = true 并且你在隐藏的 sd_imageIndicator 上设置了 sd_imageIndicator 你只在调用 self?.imageView.sd_setImage(with: imageData.url) 后才使图像可见因此你不查看指标。

尝试

            DispatchQueue.main.async { [weak self] in
                self?.imageView.isHidden = false
                self?.imageView.sd_imageIndicator = SDWebImageActivityIndicator.gray
                self?.imageView.sd_setImage(with: imageData.url)
            }