title: Transforming a subview of UIScrollView
body: <p>I am trying to reproduce an effect like the iOS 7 app switcher where I can scroll between smaller, transformed views. My current obstacle is getting the contentOffset </p>
  
  <p>In order to do this, I have added a scrollView to my view, and sized it to the bounds of the view. I then create a container view that holds on to all the 'cards' -- it is this container view to which I apply the transform.</p>
  
  <p>Anyway, the issue I am having is with adjusting <strong>where</strong> a particular card appears after it has the transform applied -- right now, I am unable to adjust the contentOffset during the transform in a manner that is smooth. </p>
  
  <p>Anyway, code would help! Here it is:</p>
  
  <pre><code>NSInteger idx = selectedCardIndex;
  
  if (TransformApplied)
  {        
      [UIView animateWithDuration:0.5 animations:^{
          [self.container setTransform:CGAffineTransformIdentity];
          [self.container setFrame:CGRectOffset(self.container.frame, (1-ScaleFactor)/2 * NumCards * ScreenWidth, 0)];
          [self.scrollView setContentSize:self.container.frame.size];
          [self.scrollView setContentOffset:CGPointMake(ScreenWidth * idx, 0) animated:NO];
  
          [self.scrollView setPagingEnabled:YES];
  
      } completion:^(BOOL finished) {
          TransformApplied = NO;
      }];
  }
  else
  {
      [UIView animateWithDuration:0.5 animations:^{
          [self.container setTransform:CGAffineTransformMakeScale(ScaleFactor, ScaleFactor)];
          [self.container setFrame:CGRectOffset(self.container.frame, (-1)*((1-ScaleFactor)/2) * NumCards * ScreenWidth, 0)];
          [self.scrollView setContentSize:CGSizeMake(ScreenWidth * ScaleFactor * NumCards, ScreenHeight * ScaleFactor)];
          [self.scrollView setContentOffset:CGPointMake(ScaleFactor * ScreenWidth * idx, 0) animated:NO];
  
  
          [self.scrollView setPagingEnabled:NO];
  
      } completion:^(BOOL finished) {
          TransformApplied = YES;
      }];
  }
  </code></pre>
  
  <p><strong>More</strong>
  I am noticing that everything is smooth when applying the identity transform, but not when applying the smaller transform, I get a weird 'jump' in the frame before the animation.</p>
  
  <p>If i comment out the content offset adjustment in the scale transform (the bottom block) then everything runs smoothly, but the contentOffset is wrong after the scale transform.</p>
  
  <p>Lastly, calling setContentOffset:animated: results in a wonky animation so that is a no-go.</p>
  
  <p>Any help greatly appreciated!!!!</p>
  
  <p><strong>UPDATE</strong></p>
  
  <p>I've looked in to anchor point/ position properties on CALayer, and I've got the animation effects working perfectly with this:</p>
  
  <pre><code>NSInteger idx = selectedCardIndex;
  
  if (TransformApplied)
  {
      [UIView dd_AnimateWithDuration:0.5 animations:^{
          [self.container setTransform:CGAffineTransformIdentity];
          [self.scrollView setContentOffset:CGPointMake(ScreenWidth * idx, 0) animated:NO];
  
          [self.scrollView setPagingEnabled:YES];
  
      } completion:^(BOOL finished) {
          TransformApplied = NO;
      }];
  }
  else
  {
      CGPoint anchor      = CGPointMake((idx * ScreenWidth + ScreenWidth/2)/CGRectGetWidth(self.container.frame), 0.5f);
      [self.container.layer setAnchorPoint:anchor];
      CGPoint position    = CGPointMake((anchor.x) * self.container.frame.size.width, self.container.layer.position.y);
      [self.container.layer setPosition:position];
  
      [UIView dd_AnimateWithDuration:0.5 animations:^{
          [self.container setTransform:CGAffineTransformMakeScale(ScaleFactor, ScaleFactor)];
  
          [self.scrollView setPagingEnabled:NO];
  
      } completion:^(BOOL finished) {
          TransformApplied = YES;
      }];
  }
  </code></pre>
  
  <p>However, now i've got to figure out a way to get rid of all the extra space in the scrollview without allowing the position of the container to change....</p>