         setSubLayers()
     }
     
+    public func scroll(with scrollView: UIScrollView) {
+        
+        let total = scrollView.contentSize.width - scrollView.bounds.width
+        let offset = scrollView.contentOffset.x
+        
+        progress = offset / total * CGFloat(pageCount - 1)
+        
+        if lastContentOffsetX < scrollView.contentOffset.x {
+            pacmanLayer.direction = .right
+        } else if lastContentOffsetX > scrollView.contentOffset.x {
+            pacmanLayer.direction = .left
+        }
+        
+        let factor = min(1, max(0, abs(scrollView.contentOffset.x - lastContentOffsetX) / scrollView.frame.size.width))
+        
+        if case .changeWithDot = pacmanColorStyle, factor == 1 {
+            pacmanLayer.color = dotColors[Int(progress)]
+        }
+        
+        pacmanLayer.position.x = pacmanOriginX + pacmanDiameter / 2 + progress * (dotDiameter + dotInterval)
+        pacmanLayer.factor = factor
+        
+        for (index, layer) in dotLayers.enumerated() {
+            update(dotLayer: layer, at: index)
+        }
+    }
+    
+    fileprivate func update(dotLayer: CAShapeLayer, at index: Int) {
+        
+        guard progress >= 0 && progress <= CGFloat(pageCount - 1) else { return }
+        
+        let originRect = CGRect(x: 0, y: 0, width: dotDiameter, height: dotDiameter)
+        
+        let offset = abs(progress - CGFloat(index))
+        let x = offset > 1 ? 1 : offset
+        let insetDis = dotDiameter / 2 * (x * x - 2 * x + 1)
+        
+        let scaleRect = originRect.insetBy(dx: insetDis, dy: insetDis)
+        dotLayer.path = UIBezierPath(ovalIn: scaleRect).cgPath
+    }
+
     fileprivate func setSubLayers() {
         
         let dotTotalWidth = dotDiameter * CGFloat(pageCount) + dotInterval * CGFloat(pageCount - 1)
         let dotOriginY = (frame.height - dotDiameter) / 2
         let dotOriginX = (frame.width - dotTotalWidth) / 2
         pacmanOriginX = dotOriginX + dotDiameter / 2 - pacmanDiameter / 2
-
+        
         var dotFrame = CGRect(x: dotOriginX, y: dotOriginY, width: dotDiameter, height: dotDiameter)
         
         dotLayers = (0..<pageCount).map { index in

        case fixed(UIColor)
        case changeWithDot
    }
    
    init(frame: CGRect, pageCount: Int) {
        super.init(frame: frame)
        
        self.pageCount = pageCount

        pacmanLayer.setNeedsDisplay()
    }
    
    required public init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
