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
·59 lines (48 loc) · 1.71 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
using System;
using CoreGraphics;
using UIKit;
using Foundation;
namespace PinchIt {
public class ViewController : UICollectionViewController {
static NSString cellClass = new NSString ("Cell");
public ViewController (UICollectionViewFlowLayout layout) : base (layout)
{
}
public override void ViewDidLoad ()
{
CollectionView.RegisterClassForCell (typeof (Cell), cellClass);
var pinchRecognizer = new UIPinchGestureRecognizer (handlePinchGesture);
handlePinchGesture (pinchRecognizer);
CollectionView.AddGestureRecognizer (pinchRecognizer);
}
public override nint GetItemsCount (UICollectionView collectionView, nint section)
{
return UIDevice.CurrentDevice.UserInterfaceIdiom == UIUserInterfaceIdiom.Pad ? 63 : 12;
}
public override UICollectionViewCell GetCell (UICollectionView collectionView, NSIndexPath indexPath)
{
return (UICollectionViewCell) collectionView.DequeueReusableCell (cellClass, indexPath);
}
public void handlePinchGesture (UIPinchGestureRecognizer sender)
{
PinchLayout pinchLayout = (PinchLayout) CollectionView.CollectionViewLayout;
switch (sender.State) {
case UIGestureRecognizerState.Began:
CGPoint initialPinchPoint = sender.LocationInView (CollectionView);
pinchLayout.pinchedCellPath = CollectionView.IndexPathForItemAtPoint (initialPinchPoint);
break;
case UIGestureRecognizerState.Changed:
pinchLayout.setPinchedCellScale ((float) sender.Scale);
pinchLayout.setPinchedCellCenter (sender.LocationInView (CollectionView));
break;
default:
CollectionView.PerformBatchUpdates (delegate
{
pinchLayout.pinchedCellPath = null;
pinchLayout.setPinchedCellScale (1.0f);
}, null);
break;
}
}
}
}