title: Image Not Centering In ScrollView after Zoom
body: <p>I am trying to centre an imgView inside a scrollView so that when I zoom in, it will remain centred properly (like the photos app).</p>
  
  <p>When the screen first loads, it is centred ok.  When I pinch and start to zoom, the position adjusts itself so the image is no longer centred.  See before and after pinch/zoom photos.
  The red is the background color of the scrollview.</p>
  
  <p><img src="https://i.stack.imgur.com/0lIkw.png" alt="Before Zoom"></p>
  
  <p><img src="https://i.stack.imgur.com/CNWNt.png" alt="After Zoom"></p>
  
  <p>Here is the code I am using to create the imgView and Center it within the scroll view.
  (MonoTouch, but should translate over to Obj-C easy)</p>
  
  <p>private void LoadPageContent(int page)
          {
              //TODO: Code to put here to load image or whateer you want to display on this panel/page</p>
  
  <pre><code>        //Each page will have it's own scrollview for scrolling and zooming that image on the page
          var panelScrollView = new UIScrollView();
          _panels.Add (panelScrollView);
  
          panelScrollView.CanCancelContentTouches=false;
          panelScrollView.ClipsToBounds = true; 
  
          panelScrollView.MinimumZoomScale = 1f;
          panelScrollView.MaximumZoomScale = 50.0f;
          panelScrollView.MultipleTouchEnabled = true;
  
          panelScrollView.ScrollEnabled = true;
          panelScrollView.UserInteractionEnabled=true;
          var ui = new UIImage (_assetImages[page], 1.0f, UIImageOrientation.Up);
  
          UIImageView imgView = new UIImageView(ui);
  
  
          panelScrollView.Frame = new RectangleF(scrollView.Frame.Width * (_numberOfPanels - 1),
                                                 0,
                                                 _pageWidthPortrait,
                                                 scrollView.Frame.Height);
  
  
          panelScrollView.BackgroundColor = UIColor.Red;
  
          //scale down image to get proper fitted imgview dimensions
          float nPercentW = (panelScrollView.Frame.Width / (float)imgView.Image.Size.Width);
          float nPercentH = (panelScrollView.Frame.Height / (float)imgView.Image.Size.Height);
          float newPercent;
          if (nPercentH &gt;= nPercentW)
          {
              //wider than it is tall
              newPercent = nPercentW;
          }
          else{
              //taller than it is wide..
              newPercent = nPercentH;
          }
          int newWidth1 = Convert.ToInt32(imgView.Image.Size.Width * newPercent);
          int newHeight = Convert.ToInt32(imgView.Image.Size.Height * newPercent);
  
          panelScrollView.ViewForZoomingInScrollView += (UIScrollView sv) =&gt; { 
              return imgView; 
          };
  
          imgView.Frame = new RectangleF(0,0,newWidth1, newHeight);
          imgView.Center = new PointF(panelScrollView.Frame.Width /2,
                                      (panelScrollView.Frame.Height/2));
  
  
    //ScaleToFill and ScaleAspect fit - i used scaleaspectfit and it had the same problem
    //I tried scaletofill but resizing the imgView to fit the proper view dimensions so it is like an aspect fit, but same problem
          imgView.ContentMode=UIViewContentMode.ScaleToFill;//ScaleAspectFit;
          imgView.UserInteractionEnabled=true;
  
          panelScrollView.ContentSize = imgView.Image.Size;
  
  
          panelScrollView.DidZoom += (object sender, EventArgs e) =&gt; {
  
      };
  
      panelScrollView.AddSubview(imgView);
      scrollView.AddSubview(panelScrollView);
  
  
      }
  </code></pre>