Skip to content

Commit

Permalink
add scrollViewDelegate variable to redirect delegate events
Browse files Browse the repository at this point in the history
  • Loading branch information
Roman Blum committed Nov 5, 2016
1 parent daafd36 commit c110ff8
Showing 1 changed file with 59 additions and 0 deletions.
59 changes: 59 additions & 0 deletions Classes/Source.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import UIKit
open class Source: NSObject {
open fileprivate(set) var sections = [SectionType]()

public var scrollViewDelegate: UIScrollViewDelegate?

public override init() {
super.init()
}
Expand Down Expand Up @@ -227,6 +229,63 @@ extension Source: UITableViewDelegate {
}
}

// MARK: - Scroll View Delegate
extension Source: UIScrollViewDelegate {

public func scrollViewDidScroll(_ scrollView: UIScrollView) {
scrollViewDelegate?.scrollViewDidScroll?(scrollView)
}

public func scrollViewDidZoom(_ scrollView: UIScrollView) {
scrollViewDelegate?.scrollViewDidZoom?(scrollView)
}

public func scrollViewWillBeginDragging(_ scrollView: UIScrollView) {
scrollViewDelegate?.scrollViewWillBeginDragging?(scrollView)
}

public func scrollViewWillEndDragging(_ scrollView: UIScrollView, withVelocity velocity: CGPoint, targetContentOffset: UnsafeMutablePointer<CGPoint>) {
scrollViewDelegate?.scrollViewWillEndDragging?(scrollView, withVelocity: velocity, targetContentOffset: targetContentOffset)
}

public func scrollViewDidEndDragging(_ scrollView: UIScrollView, willDecelerate decelerate: Bool) {
scrollViewDelegate?.scrollViewDidEndDragging?(scrollView, willDecelerate: decelerate)
}

public func scrollViewWillBeginDecelerating(_ scrollView: UIScrollView) {
scrollViewDelegate?.scrollViewWillBeginDecelerating?(scrollView)
}

public func scrollViewDidEndDecelerating(_ scrollView: UIScrollView) {
scrollViewDelegate?.scrollViewDidEndDecelerating?(scrollView)
}

public func scrollViewDidEndScrollingAnimation(_ scrollView: UIScrollView) {
scrollViewDelegate?.scrollViewDidEndScrollingAnimation?(scrollView)
}

public func viewForZooming(in scrollView: UIScrollView) -> UIView? {
return scrollViewDelegate?.viewForZooming?(in: scrollView)
}

public func scrollViewWillBeginZooming(_ scrollView: UIScrollView, with view: UIView?) {
scrollViewDelegate?.scrollViewWillBeginZooming!(scrollView, with: view)
}

public func scrollViewDidEndZooming(_ scrollView: UIScrollView, with view: UIView?, atScale scale: CGFloat) {
scrollViewDelegate?.scrollViewDidEndZooming!(scrollView, with: view, atScale: scale)
}

public func scrollViewShouldScrollToTop(_ scrollView: UIScrollView) -> Bool {
return scrollViewDelegate?.scrollViewShouldScrollToTop?(scrollView) ?? true
}

public func scrollViewDidScrollToTop(_ scrollView: UIScrollView) {
scrollViewDelegate?.scrollViewDidScrollToTop?(scrollView)
}

}

// MARK: Private method

extension Source {
Expand Down

0 comments on commit c110ff8

Please sign in to comment.