From 152da0e2d8cd3bd522fb04d1114f0930c33c9fdf Mon Sep 17 00:00:00 2001
From: 无故事王国 <841720330@qq.com>
Date: 星期四, 26 十月 2023 17:19:30 +0800
Subject: [PATCH] 修复BUG

---
 WanPai/Common/View/CommonBannerView.swift |   27 +++++++++++++++++++--------
 1 files changed, 19 insertions(+), 8 deletions(-)

diff --git a/WanPai/Common/View/CommonBannerView.swift b/WanPai/Common/View/CommonBannerView.swift
index c294047..6116ca5 100644
--- a/WanPai/Common/View/CommonBannerView.swift
+++ b/WanPai/Common/View/CommonBannerView.swift
@@ -35,14 +35,16 @@
     var interval:Double = 3
 
     private var startOffsetX:CGFloat = 0
+	private var fillBounds:CGRect?
 
     override func layoutSubviews() {
         super.layoutSubviews()
     }
 
     public func setImages(images:Array<String>,type:ImageType
-                          = .Image,imageClickBlock:@escaping (Int) -> Void) {
+						  = .Image,fillBounds:CGRect? = nil,imageClickBlock:@escaping (Int) -> Void) {
         self.type = type
+		self.fillBounds = fillBounds
         self.images = images
         self.clickBlock = imageClickBlock
         self.initLayout()
@@ -53,16 +55,23 @@
             return
         }
 
-        width = self.bounds.width
-        height = self.bounds.height
+		if fillBounds != nil{
+			width = fillBounds!.width
+			height = fillBounds!.height
+			scrollView.frame = CGRect(origin: .zero, size: fillBounds!.size)
+		}else{
+			width = self.bounds.width
+			height = self.bounds.height
+			scrollView.frame = self.bounds
+		}
 
-        scrollView.frame = self.bounds
         scrollView.contentSize = CGSize(width:width * CGFloat(images.count +
                                                               2),height:height)
         scrollView.contentOffset = CGPoint(x:width,y:0)
         scrollView.isUserInteractionEnabled = true
         scrollView.isPagingEnabled = true
 		scrollView.isScrollEnabled = images.count > 1
+		scrollView.contentInsetAdjustmentBehavior = .never
         scrollView.showsHorizontalScrollIndicator = false
         scrollView.delegate = self
         self.addSubview(scrollView)
@@ -122,15 +131,17 @@
         }
     }
 
-    func setCurrent(currIndex:Int) {
+	func setCurrent(currIndex:Int,animate:Bool = false) {
         if(currIndex < 0){
             self.currIndex = images.count - 1
         }else{
             self.currIndex = currIndex
         }
         pageControl.currentPage = self.currIndex
-        scrollView.setContentOffset(CGPoint(x:width * CGFloat(self.currIndex +
-                                                              1),y:0), animated: false)
+
+		if animate{
+			scrollView.setContentOffset(CGPoint(x:width * CGFloat(self.currIndex + 1),y:0), animated: false)
+		}
     }
 
         //给图⽚添加点击⼿势
@@ -188,7 +199,7 @@
 
     @objc func startAutoScroll(){
         if(isDisplayInScreen()){
-            setCurrent(currIndex: (currIndex + 1) % images.count)
+            setCurrent(currIndex: (currIndex + 1) % images.count,animate: true)
         }
     }
 

--
Gitblit v1.7.1