         return scrollView
     }()
     
+    public func preloadContentIfNeeded(with scrollingPercent: CGFloat) {
+        guard isEnabledPreloadContent else { return }
+        
+        if scrollingPercent > 0.5 {
+            loadPagesIfNeeded(page: leftSidePageIndex + 1)
+        } else{
+            loadPagesIfNeeded()
+        }
+    }
+    
     override public func viewDidLoad() {
         super.viewDidLoad()
         


/// A view controller that lets the user navigate between pages of content, where each page is managed by its own view controller object.
public class PagingContentViewController: UIViewController {
    fileprivate struct PagingState {
        let beginIndex: Int
        let endIndex: Int
    }
    
    fileprivate var cachedViewControllers = [UIViewController?]()
    fileprivate var leftSidePageIndex = 0
    fileprivate var numberOfPages: Int = 0
    fileprivate var isExplicityScrolling = false

    /// The object that acts as the delegate of the content view controller.
    public weak var delegate: PagingContentViewControllerDelegate?

    }
    
    fileprivate func stopScrolling() {
        explicitPaging = nil
        scrollView.layer.removeAllAnimations()
        scrollView.setContentOffset(scrollView.contentOffset, animated: false)
    }
}

// MARK:- UIScrollViewDelegate

extension PagingContentViewController: UIScrollViewDelegate {
    public func scrollViewWillBeginDragging(_ scrollView: UIScrollView) {
        explicitPaging = ExplicitPaging(oneTimeHandler: { [weak self] in
            guard let _self = self else { return }
            _self.delegate?.contentViewController(viewController: _self, willBeginPagingAt: _self.leftSidePageIndex, animated: false)
            _self.explicitPaging?.start()
        })
        leftSidePageIndex = Int(scrollView.contentOffset.x / scrollView.bounds.width)
        delegate?.contentViewController(viewController: self, willBeginManualScrollOn: leftSidePageIndex)
    }
    
    public func scrollViewDidScroll(_ scrollView: UIScrollView) {
        if let explicitPaging = explicitPaging {
            explicitPaging.fireOnetimeHandlerIfNeeded()
            leftSidePageIndex = Int(scrollView.contentOffset.x / scrollView.bounds.width)
            let normalizedPercent = min(max(0, pagingPercent), 1)
            delegate?.contentViewController(viewController: self, didManualScrollOn: leftSidePageIndex, percent: normalizedPercent)
        }
    }
    
    public func scrollViewWillBeginDecelerating(_ scrollView: UIScrollView) {
        if let explicitPaging = explicitPaging, explicitPaging.isPaging {
            delegate?.contentViewController(viewController: self, willFinishPagingAt: currentPageIndex, animated: true)
        }
    }
    
    public func scrollViewDidEndDecelerating(_ scrollView: UIScrollView) {
        if let explicitPaging = explicitPaging, explicitPaging.isPaging {
            leftSidePageIndex = Int(scrollView.contentOffset.x / scrollView.bounds.width)
            loadPagesIfNeeded()
            delegate?.contentViewController(viewController: self, didEndManualScrollOn: leftSidePageIndex)
            delegate?.contentViewController(viewController: self, didFinishPagingAt: leftSidePageIndex, animated: true)
        }
        explicitPaging = nil
    }
    
    public func scrollViewDidEndDragging(_ scrollView: UIScrollView, willDecelerate decelerate: Bool) {
        guard !decelerate else { return }
        
        if let explicitPaging = explicitPaging, explicitPaging.isPaging {
            leftSidePageIndex = Int(scrollView.contentOffset.x / scrollView.bounds.width)
            loadPagesIfNeeded()
            delegate?.contentViewController(viewController: self, didEndManualScrollOn: leftSidePageIndex)
            delegate?.contentViewController(viewController: self, willFinishPagingAt: leftSidePageIndex, animated: false)
            delegate?.contentViewController(viewController: self, didFinishPagingAt: leftSidePageIndex, animated: false)
        }
        explicitPaging = nil
    }
}

