Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 91519

Image Zooming

$
0
0

I am working on Image Zooming and Pinching from Xamarin Forms to IOS i got the desired result but first time when image load it does not fit inside screen as you can see on attachment, So any guidance or suggestion what to to do to load image inside widow.

[assembly:ExportRenderer(typeof(hared.MyDocumentViewer),
typeof(.iOS.MyDocumentViewer))]
namespace Test.iOS
{
public class MyDocumentViewer: PageRenderer
{

    UIScrollView scrollView;
    UIImageView imageView;
    float imagewith;

    protected override void OnElementChanged(VisualElementChangedEventArgs e)
    {
        base.OnElementChanged(e);

        var document = e.NewElement as MyDocumentViewer;
        var view = NativeView;

        imageView = new UIImageView(view.Bounds);

        imageView.Image = UIImage.FromFile(document.DocumentName);
        imageView.Frame = new RectangleF(0, 0, imageView.Image.CGImage.Width, imageView.Image.CGImage.Height);

        imagewith = float.Parse(View.Frame.Width.ToString());


        scrollView = new UIScrollView(
            new CGRect(10, 40, float.Parse(imagewith.ToString())
                , float.Parse(View.Frame.Height.ToString())));

        //new UILabel (new CGRect (10, 100, 320, 40))

        scrollView.ContentSize = imageView.Image.Size;
        scrollView.AddSubview(imageView);


        scrollView.MaximumZoomScale = 3f;
        scrollView.MinimumZoomScale = .1f;
        scrollView.ViewForZoomingInScrollView += (UIScrollView sv) => imageView;


        UITapGestureRecognizer doubletap = new UITapGestureRecognizer(OnDoubleTap)
        {
            NumberOfTapsRequired = 2 // double tap
        };
        scrollView.AddGestureRecognizer(doubletap);

        view.Add(scrollView);
    }

    private void OnDoubleTap(UIGestureRecognizer gesture)
    {



        if (scrollView.ZoomScale > 1)
            //scrollView.SetZoomScale (2f, true);
            scrollView.SetZoomScale(1f, true);
        else
            //scrollView.SetZoomScale (imagewith, true);
            scrollView.SetZoomScale(2f, true);

    }
}

}

)


Viewing all articles
Browse latest Browse all 91519

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>