UIScrollView Scaling in MonoTouch

I am trying to implement a zoom function using UIScrollView in MonoTouch, but I just can't get it to work.

I looked through several guides that talk about setting up a delegate, but most of it is in Obj-C, which I cannot translate to C #.

Basically, I have a UIScrollView in Interface Builder that has a UIImageView as a Subview.

I set ContentSize for UIScrollView as the full size of the image, and also set the scaling scale to min / max. Here is my code:

UIImage imgMap = new UIImage("img/map.png");
ivMap.Image = imgMap;
svMap.MinimumZoomScale = 1.0f;
svMap.MaximumZoomScale = 3.0f;
svMap.ContentSize = new System.Drawing.SizeF(ivMap.Frame.Width, ivMap.Frame.Height);

Any ideas on what I am missing?

EDIT

I created a new .xib file with the code provided by @Geoff, but still no luck, the image just scrolls, but still does not scale.

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

    UIScrollView sv = new UIScrollView (thisView.Frame);
    UIImageView iv = new UIImageView(UIImage.FromFile ("img/map.png"));

    sv.AddSubview (iv);
    sv.ContentSize = iv.Frame.Size;
    sv.MinimumZoomScale = 1.0f;
    sv.MaximumZoomScale = 3.0f;

    vwMineral.AddSubview(sv);
}
+3
source share
1

Try:

var sv = new UIScrollView (window.Frame);
var iv = new UIImageView (UIImage.FromFile ("pat.jpg"));

sv.AddSubview (iv);
sv.ContentSize = iv.Frame.Size;
sv.MinimumZoomScale = 1.0f;
sv.MaximumZoomScale = 3.0f;
sv.MultipleTouchEnabled = true;
sv.ViewForZoomingInScrollView = delegate(UIScrollView scrollView) {
    return iv;
};      

window.AddSubview (sv);
window.MakeKeyAndVisible ();
+7

Source: https://habr.com/ru/post/1792373/


All Articles