Skip to content

Commit

Permalink
add scrollview delegates
Browse files Browse the repository at this point in the history
  • Loading branch information
nghialv committed Aug 20, 2015
1 parent 69a80c1 commit 120a758
Showing 1 changed file with 41 additions and 14 deletions.
55 changes: 41 additions & 14 deletions Source/Hakuba.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,14 @@ public protocol SectionIndex {
@objc public protocol HakubaDelegate : class {
optional func scrollViewDidScroll(scrollView: UIScrollView)
optional func scrollViewWillBeginDecelerating(scrollView: UIScrollView)
optional func scrollViewDidEndDecelerating(scrollView: UIScrollView)

optional func scrollViewWillBeginDragging(scrollView: UIScrollView)
optional func scrollViewWillEndDragging(scrollView: UIScrollView, withVelocity velocity: CGPoint, targetContentOffset: UnsafeMutablePointer<CGPoint>)
optional func scrollViewDidEndDragging(scrollView: UIScrollView, willDecelerate decelerate: Bool)

optional func scrollViewDidEndScrollingAnimation(scrollView: UIScrollView)
optional func scrollViewDidScrollToTop(scrollView: UIScrollView)
}

public class Hakuba : NSObject {
Expand Down Expand Up @@ -355,6 +362,15 @@ public extension Hakuba {

// MARK - UIScrollViewDelegate
extension Hakuba {
public func tableView(tableView: UITableView, willDisplayHeaderView view: UIView, forSection section: Int) {
if section == willFloatingSection {
if let view = view as? MYHeaderFooterView {
view.didChangeFloatingState(true)
willFloatingSection = -1
}
}
}

public func scrollViewDidScroll(scrollView: UIScrollView) {
delegate?.scrollViewDidScroll?(scrollView)

Expand Down Expand Up @@ -385,23 +401,34 @@ extension Hakuba {
self.loadmoreHandler?()
}
}

public func tableView(tableView: UITableView, willDisplayHeaderView view: UIView, forSection section: Int) {
if section == willFloatingSection {
if let view = view as? MYHeaderFooterView {
view.didChangeFloatingState(true)
willFloatingSection = -1
}
}
}


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

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

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

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

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

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

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

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

// MARK - private methods
Expand Down

0 comments on commit 120a758

Please sign in to comment.