//
|
// WelfareVC.swift
|
// WanPai
|
//
|
// Created by 杨锴 on 2023/6/8.
|
//
|
|
import UIKit
|
import JQTools
|
|
class WelfareVC: BaseVC {
|
|
@IBOutlet weak var scrollView: UIScrollView!
|
@IBOutlet weak var coinCollectionView: UICollectionView!
|
|
private var timer:Timer?
|
private var timerOffsetX:Double = 0
|
private let cellW = JQ_ScreenW * 0.3794
|
|
override func viewDidLoad() {
|
super.viewDidLoad()
|
}
|
|
override func viewDidDisappear(_ animated: Bool) {
|
super.viewDidDisappear(animated)
|
timer?.invalidate()
|
}
|
|
override func viewWillDisappear(_ animated: Bool) {
|
super.viewWillDisappear(animated)
|
navigationController?.isNavigationBarHidden = false
|
}
|
|
override func viewWillAppear(_ animated: Bool) {
|
super.viewWillAppear(animated)
|
navigationController?.isNavigationBarHidden = true
|
}
|
|
override func viewDidAppear(_ animated: Bool) {
|
super.viewDidAppear(animated)
|
if timer != nil{
|
recoverTimer()
|
}else{
|
autoScroll()
|
}
|
}
|
|
override func setUI() {
|
scrollView.contentInsetAdjustmentBehavior = .never
|
coinCollectionView.delegate = self
|
coinCollectionView.dataSource = self
|
coinCollectionView.register(UINib(nibName: "WelfareCoinCCell", bundle: nil), forCellWithReuseIdentifier: "_WelfareCoinCCell")
|
}
|
|
@IBAction func userProfileAction(_ sender: UIButton) {
|
let vc = ProfileVC()
|
push(vc: vc)
|
}
|
|
@IBAction func billAction(_ sender: UIButton) {
|
let vc = WelfareBillListVC()
|
push(vc: vc)
|
}
|
|
@IBAction func couponsAction(_ sender: UIButton) {
|
let vc = WelfareCouponsListVC()
|
push(vc: vc)
|
}
|
|
@IBAction func rechargeAction(_ sender: UIButton) {
|
let vc = RechargeRecordVC()
|
push(vc: vc)
|
}
|
|
private func autoScroll(){
|
timer = Timer.scheduledTimer(timeInterval: 0.1, target: self, selector: #selector(runTimer), userInfo: nil, repeats: true)
|
timer?.fire()
|
RunLoop.current.add(timer!, forMode: .common)
|
}
|
|
@objc func runTimer(){
|
if timerOffsetX >= (JQ_ScreenW - cellW * (4 - 3)){
|
timerOffsetX = 0
|
coinCollectionView.setContentOffset(CGPoint.zero, animated: true)
|
timer?.invalidate()
|
DispatchQueue.main.asyncAfter(deadline: .now()+2.5) {
|
self.recoverTimer()
|
}
|
}
|
self.timerOffsetX += 1
|
self.coinCollectionView.setContentOffset(CGPoint(x: timerOffsetX, y: 0), animated: true)
|
}
|
|
private func recoverTimer(){
|
timer = Timer.scheduledTimer(timeInterval: 0.1, target: self, selector: #selector(runTimer), userInfo: nil, repeats: true)
|
}
|
|
func scrollViewWillBeginDragging(_ scrollView: UIScrollView) {
|
timer?.invalidate()
|
}
|
|
func scrollViewDidEndDragging(_ scrollView: UIScrollView, willDecelerate decelerate: Bool) {
|
self.timerOffsetX = max(0,scrollView.contentOffset.x)
|
self.timer?.invalidate()
|
DispatchQueue.main.asyncAfter(deadline: .now()+2.5) {
|
self.recoverTimer()
|
}
|
}
|
|
override var preferredStatusBarStyle: UIStatusBarStyle{
|
return .darkContent
|
}
|
}
|
|
extension WelfareVC:UICollectionViewDelegate{
|
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
|
let vc = WelfareRedeemGoodsDetailVC()
|
push(vc: vc)
|
}
|
}
|
|
extension WelfareVC:UICollectionViewDataSource{
|
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
|
return 4
|
}
|
|
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
|
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "_WelfareCoinCCell", for: indexPath) as! WelfareCoinCCell
|
cell.label_name.text = "\(indexPath.row)"
|
return cell
|
}
|
}
|
|
extension WelfareVC:UICollectionViewDelegateFlowLayout{
|
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumLineSpacingForSectionAt section: Int) -> CGFloat {
|
return 0
|
}
|
|
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumInteritemSpacingForSectionAt section: Int) -> CGFloat {
|
return 0
|
}
|
|
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
|
|
return CGSize(width: cellW, height: cellW)
|
}
|
}
|