зеркало из https://github.com/xamarin/ios-samples.git
[CustomCollectionViewLayoutAttributes] Fix sample to not bounce around when tapped. Fixes #12308.
This commit is contained in:
Родитель
1d12091bc2
Коммит
2aa0bf5cc7
|
@ -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)
|
||||
|
|
Загрузка…
Ссылка в новой задаче