         let offsetX = scrollView.contentOffset.x + scrollView.bounds.width * 0.5
         
         // 2. 计算pageControll的currentIndex
-        pageView.currentPage = Int(offsetX / scrollView.bounds.width)
+        pageView.currentPage = Int(offsetX / scrollView.bounds.width) % (cycleModels?.count ?? 1)
+        }
+    
+    // 防止拖拽的时候cell滚动
+    func scrollViewWillBeginDragging(_ scrollView: UIScrollView) {
+        removeCycleTimer()
+    }
+    
+    func scrollViewDidEndDragging(_ scrollView: UIScrollView, willDecelerate decelerate: Bool) {
+        addCycleTimer()
     }
 }
+
+// MARK:- 对定时器的操作方法
+extension RecommendCycleView {
+    fileprivate func addCycleTimer() {
+        cycleTimer = Timer(timeInterval: 3.0, target: self, selector: #selector(self.scrollToNext), userInfo: nil, repeats: true)
+        RunLoop.main.add(cycleTimer!, forMode: RunLoopMode.commonModes)
+    }
+    
+    fileprivate func removeCycleTimer() {
+        cycleTimer?.invalidate() // 从运行循环中移除
+        cycleTimer = nil
+    }
+    
+    @objc fileprivate func scrollToNext() {
+        // 1.获取滚动的偏移量
+        let currentOffsetX = collectionView.contentOffset.x
+        let offsetX = currentOffsetX + collectionView.bounds.width
+        
+        // 2.滚动该位置
+        collectionView.setContentOffset(CGPoint(x: offsetX, y: 0), animated: true)
+    }
+}

    @IBOutlet weak var collectionView: UICollectionView!
    
    // MARK: - 定义属性
    var cycleModels : [CycleModel]? = [CycleModel](){
        didSet{
            collectionView.reloadData()
            pageView.numberOfPages = cycleModels?.count ?? 0
        }
    }
    // MARK: 系统回调函数

    }
}

// MARK:- 遵守UICollectionView的数据源协议
extension RecommendCycleView : UICollectionViewDataSource {
    func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
        return (cycleModels?.count ?? 0) * 10000
    }
    
    func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
        let cell = collectionView.dequeueReusableCell(withReuseIdentifier: cycleViewCellID, for: indexPath) as! CollectionCycleCell
        
        cell.cycleModel = cycleModels![indexPath.item % cycleModels!.count]
        
        return cell
    }
}

// MARK:- 遵守UICollectionView的代理协议
extension RecommendCycleView : UICollectionViewDelegate{
    func scrollViewDidScroll(_ scrollView: UIScrollView) {
        // 1. 获得滚动的偏移量
