parent
858e76cf34
commit
118a3cf6e6
@ -0,0 +1,140 @@
|
||||
//
|
||||
// RefreshLoadingView.swift
|
||||
// IndieMusic
|
||||
//
|
||||
// Created by WenLei on 2024/1/17.
|
||||
//
|
||||
|
||||
import UIKit
|
||||
import MJRefresh
|
||||
import Lottie
|
||||
|
||||
class RefreshLoadingView: UIView {
|
||||
private let animationSize: CGFloat = 60.0
|
||||
private var animationView: LottieAnimationView!
|
||||
|
||||
override init(frame: CGRect) {
|
||||
super.init(frame: frame)
|
||||
self.animationView = createAnimationView()
|
||||
addSubview(animationView)
|
||||
layoutFrame()
|
||||
}
|
||||
|
||||
required init?(coder aDecoder: NSCoder) {
|
||||
fatalError("init(coder:) has not been implemented")
|
||||
}
|
||||
|
||||
private func createAnimationView() -> LottieAnimationView {
|
||||
let animationView = LottieAnimationView()
|
||||
animationView.backgroundColor = .clear
|
||||
animationView.frame = CGRect(x: 0.0, y: 0.0, width: animationSize, height: animationSize)
|
||||
animationView.loopMode = .loop
|
||||
animationView.animation = LottieAnimation.named("loading_header")
|
||||
animationView.backgroundColor = .red
|
||||
return animationView
|
||||
}
|
||||
|
||||
private func layoutFrame() {
|
||||
animationView.center = center
|
||||
}
|
||||
|
||||
// MARK: - Display
|
||||
func displayIndicator(precent: CGFloat) {
|
||||
// Implement your logic here
|
||||
}
|
||||
|
||||
func startAnimation() {
|
||||
animationView.play()
|
||||
}
|
||||
|
||||
func stopAnimation() {
|
||||
animationView.stop()
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
class RefreshHeader: MJRefreshStateHeader {
|
||||
let gifLoadingView: RefreshLoadingView = {
|
||||
let refreshLoadingView = RefreshLoadingView.init()
|
||||
|
||||
return refreshLoadingView
|
||||
}()
|
||||
|
||||
|
||||
override init(frame: CGRect) {
|
||||
super.init(frame: frame)
|
||||
lastUpdatedTimeLabel?.isHidden = true
|
||||
stateLabel?.isHidden = true
|
||||
|
||||
addSubview(self.gifLoadingView)
|
||||
}
|
||||
|
||||
required init?(coder aDecoder: NSCoder) {
|
||||
fatalError("init(coder:) has not been implemented")
|
||||
}
|
||||
|
||||
override var state: MJRefreshState {
|
||||
didSet {
|
||||
switch state {
|
||||
case .idle:
|
||||
if oldValue == .refreshing {
|
||||
gifLoadingView.alpha = 1.0
|
||||
if state != .idle { return }
|
||||
gifLoadingView.alpha = 1.0
|
||||
gifLoadingView.stopAnimation()
|
||||
} else {
|
||||
gifLoadingView.stopAnimation()
|
||||
}
|
||||
case .pulling:
|
||||
gifLoadingView.stopAnimation()
|
||||
case .refreshing:
|
||||
gifLoadingView.startAnimation()
|
||||
default:
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override func prepare() {
|
||||
super.prepare()
|
||||
mj_h = 70.0
|
||||
}
|
||||
|
||||
override func placeSubviews() {
|
||||
super.placeSubviews()
|
||||
let centerX = mj_w * 0.5
|
||||
let centerY = mj_h * 0.5
|
||||
gifLoadingView.center = CGPoint(x: centerX, y: centerY)
|
||||
}
|
||||
|
||||
override func scrollViewContentOffsetDidChange(_ change: [AnyHashable : Any]?) {
|
||||
super.scrollViewContentOffsetDidChange(change)
|
||||
if let change = change as? [String: CGPoint],
|
||||
let new = change["new"] {
|
||||
let percent = -new.y / mj_h
|
||||
gifLoadingView.displayIndicator(precent: percent)
|
||||
}
|
||||
}
|
||||
|
||||
override func scrollViewContentSizeDidChange(_ change: [AnyHashable : Any]?) {
|
||||
super.scrollViewContentSizeDidChange(change)
|
||||
// Additional implementation if needed
|
||||
|
||||
}
|
||||
|
||||
|
||||
override func scrollViewPanStateDidChange(_ change: [AnyHashable : Any]?) {
|
||||
super.scrollViewPanStateDidChange(change)
|
||||
// Additional implementation if needed
|
||||
}
|
||||
|
||||
|
||||
func backInitState() {
|
||||
// Implement the initialization state logic here
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,21 @@
|
||||
{
|
||||
"images" : [
|
||||
{
|
||||
"filename" : "home_title_btn.svg",
|
||||
"idiom" : "universal",
|
||||
"scale" : "1x"
|
||||
},
|
||||
{
|
||||
"idiom" : "universal",
|
||||
"scale" : "2x"
|
||||
},
|
||||
{
|
||||
"idiom" : "universal",
|
||||
"scale" : "3x"
|
||||
}
|
||||
],
|
||||
"info" : {
|
||||
"author" : "xcode",
|
||||
"version" : 1
|
||||
}
|
||||
}
|
After Width: | Height: | Size: 11 KiB |
Loading…
Reference in new issue