         
         
         
-        // colldectionView
+        // 注册cell
         collectionView.register(UINib(nibName: "CollectionCycleCell", bundle: nil), forCellWithReuseIdentifier: cycleViewCellID)
     }
     

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

        let offsetX = scrollView.contentOffset.x + scrollView.bounds.width * 0.5
        
        // 2. 计算pageControll的currentIndex
        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)
    }
}
