Skip to content

Instantly share code, notes, and snippets.

@prashantvc
Created January 19, 2016 16:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save prashantvc/70a28449ef39e8572ade to your computer and use it in GitHub Desktop.
Save prashantvc/70a28449ef39e8572ade to your computer and use it in GitHub Desktop.
using System;
using CoreGraphics;
using UIKit;
using Foundation;
using System.Collections.Generic;
using System.Threading.Tasks;
using System.Threading;
using Zooming;
using System.IO;
namespace Zooming
{
public partial class ViewController : UIViewController
{
ImageScrollView scrollView;
public ViewController (IntPtr handle) : base (handle)
{
}
public override void ViewDidLoad ()
{
base.ViewDidLoad ();
var image = UIImage.FromFile ("images/1.jpg");
var proImage = new ImageDetails ();
//In Project we are resizing image and Image height is given image.CGImage.Height;
proImage.Height = (float)(View.Frame.Height);//image.CGImage.Height;
proImage.Width = (float)(View.Frame.Width);//image.CGImage.Width;
proImage.Image = image;
scrollView = new ImageScrollView (proImage) {
AutoresizingMask = UIViewAutoresizing.FlexibleWidth | UIViewAutoresizing.FlexibleHeight,
};
zoomScale = (nfloat) Math.Min(View.Bounds.Size.Width / proImage.Image.Size.Width,
View.Bounds.Size.Height / proImage.Image.Size.Height);
scrollView.MaximumZoomScale = 4f;
scrollView.MinimumZoomScale = zoomScale;
UITapGestureRecognizer doubletap = new UITapGestureRecognizer (OnDoubleTap) {
NumberOfTapsRequired = 2 // double tap
};
scrollView.AddGestureRecognizer (doubletap);
View = scrollView;
scrollView.BackgroundColor = UIColor.White;
}
nfloat zoomScale;
private void OnDoubleTap (UIGestureRecognizer gesture)
{
if (scrollView.ZoomScale >= (zoomScale * 2))
scrollView.SetZoomScale (zoomScale, true);
else
scrollView.SetZoomScale (scrollView.ZoomScale * 2, true);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment