From 2aa0bf5cc7060b0ea4589c9de2150031eeaae75c Mon Sep 17 00:00:00 2001 From: Rolf Bjarne Kvinge Date: Fri, 31 May 2013 15:35:55 +0200 Subject: [PATCH] [CustomCollectionViewLayoutAttributes] Fix sample to not bounce around when tapped. Fixes #12308. --- .../AppDelegate.cs | 2 -- .../SimpleCollectionViewController.cs | 16 ++++++++++++++++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/CustomCollectionViewLayoutAttributes/AppDelegate.cs b/CustomCollectionViewLayoutAttributes/AppDelegate.cs index e7fcec1c..e458bef0 100644 --- a/CustomCollectionViewLayoutAttributes/AppDelegate.cs +++ b/CustomCollectionViewLayoutAttributes/AppDelegate.cs @@ -22,8 +22,6 @@ namespace SimpleCollectionView circleLayout = new CircleLayout (); simpleCollectionViewController = new SimpleCollectionViewController (circleLayout); - simpleCollectionViewController.CollectionView.ContentInset = new UIEdgeInsets (50, 0, 0, 0); - window.RootViewController = simpleCollectionViewController; window.MakeKeyAndVisible (); diff --git a/CustomCollectionViewLayoutAttributes/SimpleCollectionViewController.cs b/CustomCollectionViewLayoutAttributes/SimpleCollectionViewController.cs index 746e014c..dadec5cf 100644 --- a/CustomCollectionViewLayoutAttributes/SimpleCollectionViewController.cs +++ b/CustomCollectionViewLayoutAttributes/SimpleCollectionViewController.cs @@ -12,6 +12,7 @@ namespace SimpleCollectionView { static NSString animalCellId = new NSString ("AnimalCell"); List animals; + UIGestureRecognizer tapRecognizer; public SimpleCollectionViewController (UICollectionViewLayout layout) : base (layout) { @@ -25,7 +26,22 @@ namespace SimpleCollectionView { base.ViewDidLoad (); + tapRecognizer = new UITapGestureRecognizer (Tapped); + CollectionView.AddGestureRecognizer (tapRecognizer); CollectionView.RegisterClassForCell (typeof (AnimalCell), animalCellId); + CollectionView.BackgroundColor = UIColor.ScrollViewTexturedBackgroundColor; + } + + void Tapped () + { + if (tapRecognizer.State == UIGestureRecognizerState.Ended) { + var pinchPoint = tapRecognizer.LocationInView (CollectionView); + var tappedCellPath = CollectionView.IndexPathForItemAtPoint (pinchPoint); + if (tappedCellPath != null) { + animals.RemoveAt (tappedCellPath.Row); + CollectionView.DeleteItems (new NSIndexPath[] { tappedCellPath }); + } + } } public override int GetItemsCount (UICollectionView collectionView, int section)