[CustomCollectionViewLayoutAttributes] Fix sample to not bounce around when tapped. Fixes #12308.

This commit is contained in:
Rolf Bjarne Kvinge 2013-05-31 15:35:55 +02:00
Родитель 1d12091bc2
Коммит 2aa0bf5cc7
2 изменённых файлов: 16 добавлений и 2 удалений

Просмотреть файл

@ -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 ();

Просмотреть файл

@ -12,6 +12,7 @@ namespace SimpleCollectionView
{
static NSString animalCellId = new NSString ("AnimalCell");
List<IAnimal> 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)