         let offsetX = scrollView.contentOffset.x + scrollView.bounds.width * 0.5
         
         //2。计算pagecontroller  currentIndex
-        pagecontrollr.currentPage = Int(offsetX/scrollView.bounds.width)
+        pagecontrollr.currentPage = Int(offsetX/scrollView.bounds.width) % (cycleModel?.count ?? 1)
+    }
+    
+    // 用户拖拽的时候先移除定时器
+    func scrollViewWillBeginDragging(_ scrollView: UIScrollView) {
+        
+        RemoveCycleTimer()
+    }
+
+    func scrollViewDidEndDragging(_ scrollView: UIScrollView, willDecelerate decelerate: Bool) {
+        
+        addCycelTime()
+    }
+}
+
+// mark  定时器的操作方法
+extension RecommendCycleView{
+    
+    fileprivate func addCycelTime(){
+    
+        cycelTimer = Timer(timeInterval: 3.0, target: self, selector: #selector(scrollToNext), userInfo: nil, repeats: true)
+        RunLoop.main.add(cycelTimer!, forMode: .commonModes)
+    }
+    
+    fileprivate func RemoveCycleTimer(){
+    
+        // 从运行中移除定时器
+      cycelTimer?.invalidate()
+      cycelTimer = nil
+    }
+    
+    @objc private func scrollToNext(){
+    
+        // 1.获取滚动的偏移量
+        let currOffset = collectionView.contentOffset.x
+        let offset = currOffset + collectionView.bounds.width
+        
+       // 2.滚动该位置
+        collectionView.setContentOffset(CGPoint(x: offset, y: 0), animated: true)
+        
         
     }
 

            
            // 设置 pagecontrollr 的个数
            pagecontrollr.numberOfPages = cycleModel?.count ?? 0
        
        }
    
    }
    
    override func awakeFromNib() {

extension RecommendCycleView:UICollectionViewDataSource{

    func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
        return (cycleModel?.count ?? 0) * 10000
    }

    func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
        
        let cell = collectionView.dequeueReusableCell(withReuseIdentifier: kCycleCellID, for: indexPath) as! CollectionViewCycelCell
        
        let cycleModelsingel = cycleModel?[indexPath.row % (cycleModel?.count)!]
        cell.cycleModel = cycleModelsingel
        
        return cell
