title: Weird Perspective With CATransform3DMakeRotation
body: <p>I'm having an odd problem with CATransform3DMakeRotation. When the rotated view is in the center of the superview, it looks like this:</p>
  
  <p><a href="https://i.stack.imgur.com/qLCge.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/qLCge.png" alt="Valid XHTML"></a>
  </p>
  
  <p>This is how it's supposed to look. However, when it's somewhere else in the superview, say, in the lower left corner, it looks like this:</p>
  
  <p><a href="https://i.stack.imgur.com/qq4Mw.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/qq4Mw.png" alt="Valid XHTML"></a>
  </p>
  
  <p>Note that it is tilted to the right. Same thing happens when it's in the lower right corner, only that it tilts to the left. Is there some way to make it tilt the way it should all the time and in every position? The code to achieve this transformation is as follows:</p>
  
  <pre><code>    CALayer *layer = view.layer;
  
      CATransform3D aTransform = CATransform3DIdentity;
      float zDistance = 1000;
      aTransform.m34 = 1.0 / -zDistance;  
  
      self.view.layer.sublayerTransform = aTransform;
  
  
      CABasicAnimation *rotateAnim = [CABasicAnimation animationWithKeyPath:@"transform"];
      rotateAnim.fromValue= [NSValue valueWithCATransform3D:CATransform3DMakeRotation(0, 0, 0, 0)];
      rotateAnim.duration=0.12;
      rotateAnim.toValue=[NSValue valueWithCATransform3D:CATransform3DMakeRotation(20*M_PI/180, 1, 0, 0)];
  
      rotateAnim.removedOnCompletion = NO;
      rotateAnim.fillMode = kCAFillModeForwards;
      [layer addAnimation:rotateAnim forKey:@"rotateAnim"];
  </code></pre>