57 lines
1.2 KiB
Swift
57 lines
1.2 KiB
Swift
|
|
//
|
|||
|
|
// AnimatingView.swift
|
|||
|
|
// Crush
|
|||
|
|
//
|
|||
|
|
// Created by Leon on 2025/8/23.
|
|||
|
|
//
|
|||
|
|
|
|||
|
|
import UIKit
|
|||
|
|
import APNGKit
|
|||
|
|
|
|||
|
|
enum AnimatingViewType {
|
|||
|
|
case generating
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/// APNG动画,loadingView,以APNG格式的图片为主
|
|||
|
|
class AnimatingView: UIView{
|
|||
|
|
var iv : APNGImageView!
|
|||
|
|
|
|||
|
|
var type: AnimatingViewType = .generating
|
|||
|
|
|
|||
|
|
private override init(frame: CGRect) {
|
|||
|
|
super.init(frame: frame)
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
convenience init(type: AnimatingViewType = .generating) {
|
|||
|
|
self.init(frame: .zero)
|
|||
|
|
self.type = type
|
|||
|
|
setupViews()
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
required init?(coder: NSCoder) {
|
|||
|
|
fatalError("init(coder:) has not been implemented")
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
private func setupViews() {
|
|||
|
|
backgroundColor = .clear
|
|||
|
|
iv = {
|
|||
|
|
let v = APNGImageView()
|
|||
|
|
v.contentMode = .scaleAspectFit
|
|||
|
|
addSubview(v)
|
|||
|
|
v.snp.makeConstraints { make in
|
|||
|
|
make.edges.equalToSuperview()
|
|||
|
|
}
|
|||
|
|
return v
|
|||
|
|
}()
|
|||
|
|
|
|||
|
|
switch type {
|
|||
|
|
case .generating:
|
|||
|
|
if let url = Bundle.main.url(forResource: "generating", withExtension: "png") {
|
|||
|
|
let image = try? APNGImage(fileURL: url)
|
|||
|
|
iv.image = image
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
}
|