From a64b39beb6ba6ed8208d70daef2ff8872bdf265a Mon Sep 17 00:00:00 2001
From: 无故事王国 <841720330@qq.com>
Date: 星期一, 13 十一月 2023 16:01:39 +0800
Subject: [PATCH] 修复BUG

---
 WanPai/Common/View/CommonBannerView.swift |   12 ++++++++++--
 1 files changed, 10 insertions(+), 2 deletions(-)

diff --git a/WanPai/Common/View/CommonBannerView.swift b/WanPai/Common/View/CommonBannerView.swift
index 90a6b58..bacf7e2 100644
--- a/WanPai/Common/View/CommonBannerView.swift
+++ b/WanPai/Common/View/CommonBannerView.swift
@@ -104,7 +104,9 @@
 	private func startTimer(){
 		timer = Timer(timeInterval: TimeInterval(timeInterval), repeats: true, block: {[weak self] t in
 			guard let weakSelf = self else { return }
-			weakSelf.currentPage += 1
+
+			var page = weakSelf.collectionView.contentOffset.x / weakSelf.collectionView.width
+			weakSelf.currentPage = Int(page + 1)
 
 			if weakSelf.currentPage >= weakSelf.pageControl.numberOfPages{
 				weakSelf.currentPage = 0
@@ -136,13 +138,19 @@
 	}
 
 	func scrollViewDidEndDragging(_ scrollView: UIScrollView, willDecelerate decelerate: Bool) {
+		let page = scrollView.contentOffset.x / scrollView.width
+		if page.int >= pageControl.numberOfPages{
+			pageControl.currentPage = 0
+		}else{
+			pageControl.currentPage = page.int
+		}
 		print("--结束滑动")
 		timer?.fireDate = Date.init(timeIntervalSinceNow: 3.0) //3秒后开启
 	}
 
 	func scrollViewDidEndScrollingAnimation(_ scrollView: UIScrollView) {
 		let page = scrollView.contentOffset.x / scrollView.width
-		if page.int > pageControl.numberOfPages{
+		if page.int >= pageControl.numberOfPages{
 			pageControl.currentPage = 0
 		}else{
 			pageControl.currentPage = page.int

--
Gitblit v1.7.1