title: UIScrollView zooming out of a view with a -ve origin
body: <p>I have a UIScrollView. In this I have a UIView which has a frame with a negative origin - I need to limit the scroll view so that you can't scroll around the entire view..</p>
  
  <p>I have implemented Zoom in this scrollview. </p>
  
  <p>When Zooming the Scroll view will adjust the size of the Zoomable view according to the scale. BUT IT DOES NOT ADJUST THE ORIGIN.</p>
  
  <p>So if I have a view with a frame of <strong>{0, -500}, {1000, 1000}</strong> </p>
  
  <p>The I zoom out to a scale of 0.5, this will give me a new frame of <strong>{0, -500}, {500, 500}</strong></p>
  
  <p>Clearly this is not good, the entire view is zoomed out of the scrollview. I want the frame to be <strong>{0, -250}, {500, 500}</strong></p>
  
  <p>I can fix things a bit in the scrollViewDidZoom  method by adjusting the origin correctly.. This does work, but the zoom is not smooth.. Changing the origin here causes it to jump.</p>
  
  <p>I notice in the documentation for UIView it says (regarding the frame property):</p>
  
  <blockquote>
    <p>Warning: If the transform property is not the identity transform, the
    value of this property is undefined and therefore should be ignored.</p>
  </blockquote>
  
  <p>Not quite sure why that is.</p>
  
  <p>Am I approaching this problem wrong? What is the best way to fix it?</p>
  
  <p>Thanks</p>
  
  <hr>
  
  <p>Below is some source code from the test app I am using:</p>
  
  <p>In the ViewController..</p>
  
  <pre><code>- (void)viewDidLoad
  {
      [super viewDidLoad];
      self.bigView = [[BigView alloc] initWithFrame: CGRectMake(0, -400, 1000, 1000)];
  
      [self.bigScroll addSubview: bigView];
      self.bigScroll.delegate = self;
      self.bigScroll.minimumZoomScale = 0.2;
      self.bigScroll.maximumZoomScale = 5;
      self.bigScroll.contentSize = bigView.bounds.size;
  }
  
  -(UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView  {
      return bigView;
  }
  
  - (void)scrollViewDidZoom:(UIScrollView *)scrollView {    
  //    bigView.frame = CGRectMake(0, -400 * scrollView.zoomScale,
  //                               bigView.frame.size.width, bigView.frame.size.height);
  
      bigView.center = CGPointMake(500 * scrollView.zoomScale, 100 * scrollView.zoomScale);
  }
  </code></pre>
  
  <p>And then in the View...</p>
  
  <pre><code>- (void)drawRect:(CGRect)rect
  {
      // Drawing code
      CGContextRef ctx = UIGraphicsGetCurrentContext();
  
      CGContextSetFillColorWithColor(ctx, [UIColor whiteColor].CGColor);
      CGContextSetStrokeColorWithColor(ctx, [UIColor whiteColor].CGColor);
      CGContextFillRect(ctx, CGRectMake(100, 500, 10, 10));
  
      for (int i = 0; i &lt; 1000; i += 100) {
          CGContextStrokeRect(ctx, CGRectMake(0, i, 1000, 3));        
      }
  }
  </code></pre>
  
  <p>Note that here the jumpiness is more apparent at larger zoom scales. In my real app where there is much more drawing and processing going on the jump is more apparent at all times. </p>