1
This commit is contained in:
parent
49c3b9b3c9
commit
f903e4cfae
@ -7,6 +7,7 @@
|
|||||||
|
|
||||||
import UIKit
|
import UIKit
|
||||||
import SnapKit
|
import SnapKit
|
||||||
|
import YYText
|
||||||
|
|
||||||
class FAPayRetainAlert: FABaseAlert {
|
class FAPayRetainAlert: FABaseAlert {
|
||||||
|
|
||||||
@ -164,6 +165,10 @@ extension FAPayRetainAlert {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static let defaultCountdownSeconds = 4 * 60 * 60
|
||||||
|
private var countdownTimer: Timer?
|
||||||
|
private var remainingSeconds: Int = 0
|
||||||
|
|
||||||
private let prefixLabel = UILabel()
|
private let prefixLabel = UILabel()
|
||||||
private let suffixLabel = UILabel()
|
private let suffixLabel = UILabel()
|
||||||
private let timeStackView = UIStackView()
|
private let timeStackView = UIStackView()
|
||||||
@ -178,6 +183,10 @@ extension FAPayRetainAlert {
|
|||||||
setupView()
|
setupView()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
deinit {
|
||||||
|
stopCountdown()
|
||||||
|
}
|
||||||
|
|
||||||
required init?(coder: NSCoder) {
|
required init?(coder: NSCoder) {
|
||||||
fatalError("init(coder:) has not been implemented")
|
fatalError("init(coder:) has not been implemented")
|
||||||
}
|
}
|
||||||
@ -191,6 +200,15 @@ extension FAPayRetainAlert {
|
|||||||
secondView.setText(countdown.seconds)
|
secondView.setText(countdown.seconds)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override func didMoveToWindow() {
|
||||||
|
super.didMoveToWindow()
|
||||||
|
if window != nil {
|
||||||
|
startCountdown()
|
||||||
|
} else {
|
||||||
|
stopCountdown()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private func setupView() {
|
private func setupView() {
|
||||||
let mainStack = UIStackView()
|
let mainStack = UIStackView()
|
||||||
mainStack.axis = .horizontal
|
mainStack.axis = .horizontal
|
||||||
@ -231,6 +249,42 @@ extension FAPayRetainAlert {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 每次展示时从 4 小时开始倒计时
|
||||||
|
private func startCountdown() {
|
||||||
|
stopCountdown()
|
||||||
|
remainingSeconds = Self.defaultCountdownSeconds
|
||||||
|
updateTimeLabels()
|
||||||
|
countdownTimer = Timer.scheduledTimer(timeInterval: 1,
|
||||||
|
target: YYTextWeakProxy(target: self),
|
||||||
|
selector: #selector(handleCountdownTimer),
|
||||||
|
userInfo: nil,
|
||||||
|
repeats: true)
|
||||||
|
}
|
||||||
|
|
||||||
|
private func stopCountdown() {
|
||||||
|
countdownTimer?.invalidate()
|
||||||
|
countdownTimer = nil
|
||||||
|
}
|
||||||
|
|
||||||
|
@objc private func handleCountdownTimer() {
|
||||||
|
guard remainingSeconds > 0 else {
|
||||||
|
updateTimeLabels()
|
||||||
|
stopCountdown()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
remainingSeconds -= 1
|
||||||
|
updateTimeLabels()
|
||||||
|
}
|
||||||
|
|
||||||
|
private func updateTimeLabels() {
|
||||||
|
let hours = remainingSeconds / 3600
|
||||||
|
let minutes = (remainingSeconds % 3600) / 60
|
||||||
|
let seconds = remainingSeconds % 60
|
||||||
|
hourView.setText(String(format: "%02d", hours))
|
||||||
|
minuteView.setText(String(format: "%02d", minutes))
|
||||||
|
secondView.setText(String(format: "%02d", seconds))
|
||||||
|
}
|
||||||
|
|
||||||
private final class TimeBoxView: UIView {
|
private final class TimeBoxView: UIView {
|
||||||
private let label = UILabel()
|
private let label = UILabel()
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user