         viewControllers = []
         super.init(coder: aDecoder)
     }
+    
+    /// Previous scroll view content offset.
+    fileprivate var previousContentOffset: CGFloat = 0
+    
+    /// The number of views used in the scrollViewPool.
+    fileprivate let viewPoolCount = 3
     
     /**
      An initializer that accepts an Array of UIViewControllers.

    @IBInspectable
    open let scrollView = UIScrollView()
    
    /// Previous scroll view content offset.
    fileprivate var previousContentOffset: CGFloat = 0
    
    /// An Array of UIViewControllers.
    open var viewControllers: [UIViewController] {
        didSet {


extension PageMenuController: UIScrollViewDelegate {
    @objc
    open func scrollViewDidEndDecelerating(_ scrollView: UIScrollView) {
        let n = viewControllers.count
        let x = scrollView.contentOffset.x
        let w = scrollView.width
        let p = Int(floor((scrollView.contentOffset.x - w / 2) / w) + 1)
        print(selectedIndex, p)
        
        selectedIndex = p
        
        removeViewControllers()
        prepareViewControllers()
