Find file History
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.
CollectionViewZoom reorganizing files into recipes folder Mar 7, 2018

id title brief sdk
Zoom a Collection View
This recipe shows how to use a gesture recognizer to allow the user to zoom in a Collection View.


To allow a user to zoom in a Collection View, you first need to add a gesture recognizer to your View:

public override void ViewDidLoad ()
		base.ViewDidLoad ();

		UIPinchGestureRecognizer pinch = new UIPinchGestureRecognizer (handlePinchGesture);
		this.CollectionView.AddGestureRecognizer (pinch);

Then add a handler method to respond to the gesture:

public void handlePinchGesture (UIPinchGestureRecognizer gesture)
	if (gesture.State == UIGestureRecognizerState.Began)
		scaleStart = this.scale;
	else if (gesture.State == UIGestureRecognizerState.Changed)
		this.scale = scaleStart * gesture.Scale;

		this.CollectionView.CollectionViewLayout.InvalidateLayout ();

Finally, in the Collection View's delegate, you will need to override the GetSizeForItem() method to apply the zoom's scale factor to the size of each item:

public override System.Drawing.CGSize GetSizeForItem (UICollectionView collectionView, UICollectionViewLayout layout, NSIndexPath indexPath)
		return new System.Drawing.CGSize (50 * parent.scale, 50 * parent.scale);