This repository was archived by the owner on Apr 29, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
/
Copy pathViewController.cs
executable file
·69 lines (56 loc) · 1.79 KB
/
ViewController.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
using System;
using CoreGraphics;
using Foundation;
using UIKit;
namespace CircleLayout {
public partial class ViewController : UICollectionViewController {
static NSString cellClass = new NSString ("Cell");
int cellCount = 20;
public ViewController (UICollectionViewLayout layout) : base (layout)
{
}
public override void ViewDidLoad ()
{
base.ViewDidLoad ();
CollectionView.RegisterClassForCell (typeof (Cell), cellClass);
CollectionView.AddGestureRecognizer (new UITapGestureRecognizer (HandleTapGesture));
CollectionView.ReloadData ();
CollectionView.BackgroundColor = UIColor.DarkGray;
}
//adjust the status bar in ios7 to use default or light style
public override UIStatusBarStyle PreferredStatusBarStyle ()
{
return UIStatusBarStyle.LightContent;
}
public override nint GetItemsCount (UICollectionView collectionView, nint section)
{
return cellCount;
}
public override UICollectionViewCell GetCell (UICollectionView collectionView, NSIndexPath indexPath)
{
return (UICollectionViewCell) collectionView.DequeueReusableCell (cellClass, indexPath);
}
void HandleTapGesture (UITapGestureRecognizer sender)
{
if (sender.State != UIGestureRecognizerState.Ended)
return;
CGPoint initialPinchPoint = sender.LocationInView (CollectionView);
NSIndexPath tappedCellPath = CollectionView.IndexPathForItemAtPoint (initialPinchPoint);
if (tappedCellPath != null) {
cellCount--;
CollectionView.PerformBatchUpdates (delegate
{
CollectionView.DeleteItems (new NSIndexPath [] { tappedCellPath });
}, null);
} else {
cellCount++;
CollectionView.PerformBatchUpdates (delegate
{
CollectionView.InsertItems (new NSIndexPath [] {
NSIndexPath.FromItemSection (0, 0)
});
}, null);
}
}
}
}