class SwipeTitleLayout
Attributes
delegate[RW]
Public Instance Methods
centerOfElementAtIndex(index)
click to toggle source
# File lib/swipe_title/swipe_title_layout.rb, line 74 def centerOfElementAtIndex index unless @centerPostions.has_key? index pos = index * collectionView.frame.size.width @centerPostions[index] = pos end @centerPostions[index] end
collectionViewContentSize()
click to toggle source
# File lib/swipe_title/swipe_title_layout.rb, line 29 def collectionViewContentSize width = @titles * collectionView.frame.size.width size = CGSizeMake(width, collectionView.frame.size.height) collectionView.contentSize = size size end
init()
click to toggle source
Calls superclass method
# File lib/swipe_title/swipe_title_layout.rb, line 9 def init super @centerPostions = {} self end
layoutAttributesForElementsInRect(rect)
click to toggle source
# File lib/swipe_title/swipe_title_layout.rb, line 36 def layoutAttributesForElementsInRect rect objs = [] @titles.times do |t| indexPath = NSIndexPath.indexPathForItem(t, inSection:0) objs << layoutAttributesForItemAtIndexPath(indexPath) end objs end
layoutAttributesForItemAtIndexPath(path)
click to toggle source
# File lib/swipe_title/swipe_title_layout.rb, line 50 def layoutAttributesForItemAtIndexPath path UICollectionViewLayoutAttributes. layoutAttributesForCellWithIndexPath(path).tap do |obj| x = (path.row + 0.5) * collectionView.frame.size.width y = (collectionView.frame.size.height - 14) / 2 obj.center = [x, y] obj.size = [collectionView.frame.size.width, collectionView.frame.size.height - 14] end end
prepareLayout()
click to toggle source
Calls superclass method
# File lib/swipe_title/swipe_title_layout.rb, line 19 def prepareLayout super @titles = if collectionView.numberOfSections > 0 collectionView.numberOfItemsInSection 0 else 0 end end
rows()
click to toggle source
# File lib/swipe_title/swipe_title_layout.rb, line 5 def rows @rows end
scrollViewDidScroll(pos)
click to toggle source
# File lib/swipe_title/swipe_title_layout.rb, line 46 def scrollViewDidScroll pos index = selectElementAtPosition pos end
shouldInvalidateLayoutForBoundsChange(oldBounds)
click to toggle source
# File lib/swipe_title/swipe_title_layout.rb, line 15 def shouldInvalidateLayoutForBoundsChange oldBounds true end
targetContentOffsetForProposedContentOffset(proposedOffset, withScrollingVelocity: velocity)
click to toggle source
# File lib/swipe_title/swipe_title_layout.rb, line 62 def targetContentOffsetForProposedContentOffset proposedOffset, withScrollingVelocity: velocity offset = proposedOffset index = selectElementAtPosition proposedOffset.x offset.x = centerOfElementAtIndex index offset proposedOffset end
Private Instance Methods
centerOfPage?(pos)
click to toggle source
# File lib/swipe_title/swipe_title_layout.rb, line 85 def centerOfPage? pos @centerPostions.has_value? pos.round end
indexOfElementAtPosition(position)
click to toggle source
# File lib/swipe_title/swipe_title_layout.rb, line 99 def indexOfElementAtPosition position (position / collectionView.frame.size.width).round end
selectElementAtPosition(pos)
click to toggle source
# File lib/swipe_title/swipe_title_layout.rb, line 89 def selectElementAtPosition pos index = indexOfElementAtPosition pos if index != delegate.selectedIndex delegate.selectedIndex = index end index end