class SwipeCollectionViewController

Constants

CELL_ID

Attributes

delegate[RW]
selectedIndex[RW]

Public Instance Methods

collectionView(view, numberOfItemsInSection: section) click to toggle source
# File lib/swipe_title/swipe_collection_view_controller.rb, line 60
def collectionView view, numberOfItemsInSection: section
  @titles.length
end
didSelectRowAtIndex(index) click to toggle source
# File lib/swipe_title/swipe_collection_view_controller.rb, line 64
def didSelectRowAtIndex index
  delegate.didSelectRowAtIndex index if delegate.responds_to?(:didSelectRowAtIndex)
end
initWithCollectionViewLayout(layout) click to toggle source
Calls superclass method
# File lib/swipe_title/swipe_collection_view_controller.rb, line 19
def initWithCollectionViewLayout layout
  super

  collectionView.backgroundColor = UIColor.clearColor
  collectionView.showsHorizontalScrollIndicator = false
  
  selectedIndex = 0

  @layout = layout
  @layout.delegate = self

  @titles = []

  collectionView.registerClass TitlePage,
    forCellWithReuseIdentifier: CELL_ID

  self
end
initWithFrame(frame) click to toggle source
# File lib/swipe_title/swipe_collection_view_controller.rb, line 8
def initWithFrame frame
  initWithCollectionViewLayout SwipeTitleLayout.new

  collectionView.frame = CGRectMake(frame.origin.x,
    frame.origin.y,
    frame.size.width,
    frame.size.height)

  self
end
reloadData() click to toggle source
# File lib/swipe_title/swipe_collection_view_controller.rb, line 56
def reloadData
  collectionView.reloadData
end
scrollToItemAtIndex(index) click to toggle source
# File lib/swipe_title/swipe_collection_view_controller.rb, line 43
def scrollToItemAtIndex index
  return if index > @titles.length - 1
  
  self.selectedIndex = index

  p = CGPointMake(@layout.centerOfElementAtIndex(index), 0)
  collectionView.setContentOffset p, animated: true
end
scrollViewDidScroll(scrollView) click to toggle source
# File lib/swipe_title/swipe_collection_view_controller.rb, line 88
def scrollViewDidScroll scrollView
  offset = scrollView.contentOffset

  offset.x = 0 if offset.x < 0
  offset.x = scrollView.contentSize.width - scrollView.frame.size.width if offset.x + scrollView.frame.size.width > scrollView.contentSize.width

  scrollView.contentOffset = offset
end
scrollViewWillBeginDragging(scrollView) click to toggle source
# File lib/swipe_title/swipe_collection_view_controller.rb, line 78
def scrollViewWillBeginDragging scrollView
  delegate.swipeBegan
end
scrollViewWillEndDragging(scrollView, withVelocity: velocity, targetContentOffset: targetContentOffset) click to toggle source
# File lib/swipe_title/swipe_collection_view_controller.rb, line 82
def scrollViewWillEndDragging scrollView,
  withVelocity: velocity,
  targetContentOffset: targetContentOffset
  delegate.swipeEnded
end
selectedIndex=(index) click to toggle source
# File lib/swipe_title/swipe_collection_view_controller.rb, line 52
def selectedIndex= index
  delegate.swipeTitleControllerSelectedIndex(self, index)
end
titles=(titles) click to toggle source
# File lib/swipe_title/swipe_collection_view_controller.rb, line 38
def titles= titles
  @titles = titles
  reloadData
end