wake-ios/wake/View/Blind/Apng.swift
2025-08-28 10:47:57 +08:00

38 lines
1.1 KiB
Swift
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import SwiftUI
import UIKit
// UIImageViewAPNG
struct APNGView: UIViewRepresentable {
let imageName: String
@Binding var isAnimating: Bool
func makeUIView(context: Context) -> UIImageView {
let imageView = UIImageView()
// APNG
if let image = UIImage(named: imageName) {
imageView.image = image
//
imageView.animationImages = image.images
//
imageView.animationDuration = image.duration
// isAnimating
if isAnimating {
imageView.startAnimating()
}
}
return imageView
}
func updateUIView(_ uiView: UIImageView, context: Context) {
// isAnimating
if isAnimating {
if !uiView.isAnimating {
uiView.startAnimating()
}
} else {
uiView.stopAnimating()
}
}
}