title: Scale UIView not from center, but from bottom right corner using CATransform3DScale
body: <p>I want to scale (shrink) profile picture based upon scroll. But, the main thing is that, I want to scale it not from center point but from the bottom right angle. Means, that the bottom right angle should be fixed and image should be shrink from left and top edge as shown in image:</p>
  
  <pre><code>—————————————————
  |               |
  |    ———————————-    
  |    |          |
  |    |          |
  |    |     —————|
  |    |     |    |
  |    |     |    |
  —————————————————
  </code></pre>
  
  <p>Here is what I doing. Profile picture is named <code>imgVwProfilePic</code>:</p>
  
  <pre><code>- (void)scrollViewDidScroll:(UIScrollView *)scrollView
  {
      CGFloat offset = scrollView.contentOffset.y;
      CATransform3D avatarTransform = CATransform3DIdentity; 
      CATransform3D headerTransform = CATransform3DIdentity;
  
      viewHeader.alpha = 1.0;
  
      // PULL DOWN -----------------
  
      if(offset &lt; 0)
      {
          CGFloat headerScaleFactor = -(offset) / CGRectGetHeight(viewHeader.bounds);
          int headerSizevariation = ((CGRectGetHeight(viewHeader.bounds) * (1.0 + headerScaleFactor)) - CGRectGetHeight(viewHeader.bounds))/2.0;
          headerTransform = CATransform3DTranslate(headerTransform, 0, headerSizevariation, 0);
          headerTransform = CATransform3DScale(headerTransform, 1.0 + headerScaleFactor, 1.0 + headerScaleFactor, 0);
  
          viewHeader.layer.transform = headerTransform;
      }
  
      // SCROLL UP/DOWN ------------
  
      else
      {
          CGFloat offset_HeaderStop = viewHeader.frame.size.height;
          headerTransform = CATransform3DTranslate(headerTransform, 0, MAX(-offset_HeaderStop, -offset), 0);
  
          float avatarScaleFactor = (MIN(offset_HeaderStop, offset)) / CGRectGetHeight(imgVwProfilePic.bounds) / 3.8; //1.4// Slow down the animation
          float avatarSizeVariation = ((CGRectGetHeight(imgVwProfilePic.bounds) * (1.0 + avatarScaleFactor)) - CGRectGetHeight(imgVwProfilePic.bounds)) / 2.0;
  
          avatarTransform = CATransform3DTranslate(avatarTransform, 0, avatarSizeVariation, 0);
          avatarTransform = CATransform3DScale(avatarTransform, 1.0 - avatarScaleFactor, 1.0 - avatarScaleFactor, 0);
  
          if(offset &lt;= offset_HeaderStop){
              if(imgVwProfilePic.layer.zPosition &lt; viewHeader.layer.zPosition){
                  viewHeader.layer.zPosition = 0;
              }
          }
  
          else {
              if (imgVwProfilePic.layer.zPosition &gt;= viewHeader.layer.zPosition){
                  viewHeader.layer.zPosition = 2;
              }
          }
      }
  
      // Apply Transformations
      viewHeader.layer.transform = headerTransform;
      imgVwProfilePic.layer.transform = avatarTransform;
  }
  </code></pre>
  
  <p>Now, I came t know that I will have to set anchor point for that image view. But I have no idea where I will set it. I set it in <code>viewDidLoad</code>, but it changes the original frame of that image view.</p>
  
  <pre><code>- (void)viewDidLoad 
  {
      imgVwProfilePic.layer.anchorPoint = CGPointMake(1, 1); // 1,1 for bottom right corner...
  }
  </code></pre>