     
     public func scrollViewDidScroll(_ scrollView: UIScrollView) {
         //cell滑动过程中，当前页面判断
+        guard actualShows > 0 else {
+            return
+        }
         let index = currentIndex() % actualShows
         delegate?.collectionViewDidEndDecelerating?(index: index)
     }
     
-   public func scrollViewDidEndDragging(_ scrollView: UIScrollView, willDecelerate decelerate: Bool) {
+    public func scrollViewDidEndDragging(_ scrollView: UIScrollView, willDecelerate decelerate: Bool) {
         if autoScroll {//启动定时器
             start()
         }
     }
     
-   public func scrollViewDidEndDecelerating(_ scrollView: UIScrollView) {
-       let index = autoScrolling ? (currentIndex() + 1) % actualShows : currentIndex() % actualShows
+    public func scrollViewDidEndDecelerating(_ scrollView: UIScrollView) {
+        guard actualShows > 0 else {
+            return
+        }
+        let index = autoScrolling ? (currentIndex() + 1) % actualShows : currentIndex() % actualShows
         delegate?.collectionViewDidEndDecelerating?(index: index)
-       //页面滑动（无论是自动滑动还是手动拖拽）结束，修改状态
-       autoScrolling = autoScroll
+        //页面滑动（无论是自动滑动还是手动拖拽）结束，修改状态
+        autoScrolling = autoScroll
     }
 }

    //滚动方向,默认横向
    private var scrollDirection: UICollectionViewScrollDirection = .horizontal {
        willSet {
           collectionViewLayout.scrollDirection = newValue
        }
    }
    

                collectionView.scrollToItem(at: IndexPath(item: targetIndex, section: 0), at: scrollPosition, animated: true)
            }
        } else {//正常从中间往后偏移
            collectionView.scrollToItem(at: IndexPath(item: targetIndex, section: 0), at: scrollPosition, animated: true)
        }
        
        scrollViewDidEndDecelerating(collectionView)
