ScrollViewCustomHorizontalPageSize

public protocol ScrollViewCustomHorizontalPageSize : UIScrollViewDelegate

Protocol that simplifies custom page size configuration for UIScrollView. Sadly, can not be done better due to protocol extensions limitations - https://stackoverflow.com/questions/39487168/non-objc-method-does-not-satisfy-optional-requirement-of-objc-protocol

Note

Set .decelerationRate to UIScrollViewDecelerationRateFast for a fancy scrolling animation.
  • Custom page size

    Declaration

    Swift

    var pageSize: CGFloat { get }
  • getCurrentPage(scrollView:) Default implementation

    Helper method to get current page fraction

    Default Implementation

    Declaration

    Swift

    func getCurrentPage(scrollView: UIScrollView) -> CGFloat
  • Helper method to get targetContentOffset. Usage:

    func scrollViewWillEndDragging(_ scrollView: UIScrollView, withVelocity velocity: CGPoint, targetContentOffset: UnsafeMutablePointer<CGPoint>) {
        targetContentOffset.pointee.x = getTargetContentOffset(scrollView: scrollView, velocity: velocity)
    }
    

    Default Implementation

    Declaration

    Swift

    func getTargetContentOffset(scrollView: UIScrollView, velocity: CGPoint) -> CGFloat
  • Must be implemented. See getTargetContentOffset for more info.

    Declaration

    Swift

    func scrollViewWillEndDragging(_ scrollView: UIScrollView, withVelocity velocity: CGPoint, targetContentOffset: UnsafeMutablePointer<CGPoint>)