UIImageView zoom in combination with UIScrollView
Double Tap
Section titled “Double Tap”private float minScale = 1f;private float doubleTapScale = 2f;private float maxScale = 4f;
private void SetUpDoubleTapZoom(){ imageViewToZoom.ContentMode = UIViewContentMode.ScaleAspectFit; scrollView.MaximumZoomScale = maxScale; scrollView.MinimumZoomScale = minScale;
var doubleTap = new UITapGestureRecognizer(OnDoubleTap) { NumberOfTapsRequired = 2 };
scrollView.AddGestureRecognizer(doubleTap);}
private void OnDoubleTap(UIGestureRecognizer gesture){ scrollView.ZoomScale = (scrollView.ZoomScale.Equals(minScale)) ? doubleTapScale : minScale;}Pinch gesture zoom
Section titled “Pinch gesture zoom”private float minScale = 1f;private float maxScale = 4f;
private void SetUpPinchGestureZoom(){ imageViewToZoom.ContentMode = UIViewContentMode.ScaleAspectFit;
scrollView.MaximumZoomScale = maxScale; scrollView.MinimumZoomScale = minScale;
scrollView.ViewForZoomingInScrollView += (UIScrollView sv) => { return imageViewToZoom; };}Remarks
Section titled “Remarks”The UIImageView has to be within a scrollview in order for this to work.
The DoubleTap method will toggle between the minScale and the doubleTapScale.