93 lines
2.5 KiB
Swift
93 lines
2.5 KiB
Swift
//
|
|
// CreateBubbleDoneView.swift
|
|
// QuickLocation
|
|
//
|
|
|
|
import UIKit
|
|
import RxSwift
|
|
import RxCocoa
|
|
|
|
class CreateBubbleDoneView: UIView {
|
|
|
|
var disposeBag = DisposeBag()
|
|
|
|
let heroView = BubbleHeroView()
|
|
let popupBtn = UIButton(type: .custom)
|
|
|
|
private var countdownTimer: Timer?
|
|
private var endDate: Date = Date()
|
|
|
|
private let clockImage = UIImageView()
|
|
private let timeLab = UILabel()
|
|
|
|
func startCountdown(endDate: Date) {
|
|
self.endDate = endDate
|
|
countdownTimer?.invalidate()
|
|
countdownTimer = Timer.scheduledTimer(withTimeInterval: 1, repeats: true) { [weak self] _ in
|
|
self?.updateTime()
|
|
}
|
|
updateTime()
|
|
}
|
|
|
|
private func updateTime() {
|
|
let remaining = endDate.timeIntervalSince(Date())
|
|
if remaining <= 0 {
|
|
timeLab.text = "00:00:00"
|
|
countdownTimer?.invalidate()
|
|
countdownTimer = nil
|
|
return
|
|
}
|
|
let hours = Int(remaining) / 3600
|
|
let minutes = (Int(remaining) % 3600) / 60
|
|
let seconds = Int(remaining) % 60
|
|
timeLab.text = String(format: "%02d:%02d:%02d", hours, minutes, seconds)
|
|
}
|
|
|
|
private func setupUI() {
|
|
addSubview(heroView)
|
|
addSubview(clockImage)
|
|
clockImage.addSubview(timeLab)
|
|
addSubview(popupBtn)
|
|
|
|
heroView.layoutChain
|
|
.top(33)
|
|
.leading(30)
|
|
.trailing(30)
|
|
.heightToWidth(1)
|
|
|
|
clockImage.image = UIImage(named: "Bubble/clock")
|
|
clockImage.contentMode = .scaleAspectFit
|
|
clockImage.layoutChain
|
|
.topToBottomOfView(heroView, offset: 8)
|
|
.centerX()
|
|
.width(200)
|
|
.height(120)
|
|
|
|
timeLab.font = .systemFont(ofSize: 28, weight: .heavy)
|
|
timeLab.textColor = .white
|
|
timeLab.textAlignment = .center
|
|
timeLab.layoutChain.centerX(clockImage).centerY(clockImage, offset: 4)
|
|
|
|
popupBtn.setTitle("弹出气泡", for: .normal)
|
|
popupBtn.setTitleColor(.white, for: .normal)
|
|
popupBtn.titleLabel?.font = FontManager.boboBold(18)
|
|
popupBtn.backgroundColor = UIColor(hexStr: "#16B3FF")
|
|
popupBtn.layer.cornerRadius = 16
|
|
popupBtn.layoutChain.left(20).right(20).bottom(34).height(56)
|
|
}
|
|
|
|
override init(frame: CGRect) {
|
|
super.init(frame: .zero)
|
|
backgroundColor = .white
|
|
setupUI()
|
|
}
|
|
|
|
required init?(coder aDecoder: NSCoder) {
|
|
fatalError("init(coder:) has not been implemented")
|
|
}
|
|
|
|
deinit {
|
|
countdownTimer?.invalidate()
|
|
}
|
|
}
|