Sha256: fa34937e8912e7fcc444d001a637f68e000420827415318adf58899e303ddadf

Contents?: true

Size: 1.21 KB

Versions: 1

Compression:

Stored size: 1.21 KB

Contents

class ViewController < UICollectionViewController
  CellIdentifier = 'MyCell'

  def viewDidLoad
    @cell_count = 20
    tap = UITapGestureRecognizer.alloc.initWithTarget(self, action: :'handleTapGesture:')
    collectionView.addGestureRecognizer(tap)
    collectionView.registerClass(Cell, forCellWithReuseIdentifier:CellIdentifier)
    collectionView.backgroundColor = UIColor.scrollViewTexturedBackgroundColor
  end

  def collectionView(view, numberOfItemsInSection:section)
    @cell_count
  end

  def collectionView(view, cellForItemAtIndexPath:path)
    view.dequeueReusableCellWithReuseIdentifier(CellIdentifier, forIndexPath:path)
  end

  def handleTapGesture(sender)
    if sender.state == UIGestureRecognizerStateEnded
      pinch_point = sender.locationInView(collectionView)
      path = collectionView.indexPathForItemAtPoint(pinch_point)
      if path
        @cell_count -= 1
        collectionView.performBatchUpdates(lambda { collectionView.deleteItemsAtIndexPaths([path]) }, completion:nil)
      else
        @cell_count += 1
        collectionView.performBatchUpdates(lambda { collectionView.insertItemsAtIndexPaths([NSIndexPath.indexPathForItem(0, inSection:0)]) }, completion:nil)
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
rubymotionr-0.0.1 spec/multiple-rubymotion-apps/CircleLayout/app/view_controller.rb