title: Setting correct frame of a newly created CAShapeLayer
body: <p>In short:</p>
  
  <ol>
  <li>Apple does NOT set the <code>frame</code> or <code>bounds</code> for a <code>CAShapeLayer</code> automatically (and Apple HAS NOT implemented an equivalent of <code>[UIView sizeThatFits]</code>)</li>
  <li>If you set the frame using the size of the bounding-box of the path ... everything goes wrong. No matter how you try to set it, it screws-up the path</li>
  </ol>
  
  <p>So, what's the correct way to programmatically set the frame of a newly-created <code>CAShapeLayer</code> with a newly-added <code>CGPath</code> ? Apple's docs are silent on the matter.</p>
  
  <p>Things I've tried, that don't work:</p>
  
  <ol>
  <li>Create a <code>CAShapeLayer</code></li>
  <li>Create a <code>CGPath</code>, add it to the layer</li>
  <li>Check the layer's <code>frame</code> - it's <code>{{0,0},{0,0}}</code></li>
  <li>Set: <code>layer.frame = CGPathGetBoundingBox( layer.path )</code></li>
  <li><p>Frame is now correct, but the path is now DOUBLE offset - changing the <code>frame</code> causes the path to effectively be shifted an extra <code>(x,y)</code> pixels</p></li>
  <li><p>Set: <code>layer.bounds = CGPathGetBoundingBox( layer.path )</code></p></li>
  <li>...it all goes nuts. Nothing makes sense any more</li>
  <li>Try fixing it by doing <code>layer.position = CGPathGetBoundingBox( layer.path ).origin</code></li>
  <li>...no dice; still nuts.</li>
  </ol>
  
  <p>One thing I've tried that DID work, but causes problems elsewhere:</p>
  
  <p>EDIT: this BREAKS as soon as you auto-rotate the screen. My guess: Apple's auto-rotate <em>requires</em> control of the "transform" property.</p>
  
  <ol>
  <li>Create a <code>CAShapeLayer</code></li>
  <li>Create a <code>CGPath</code>, add it to the layer</li>
  <li>Check the layer's frame - it's <code>{{0,0},{0,0}}</code></li>
  <li>Set: <code>layer.frame = CGPathGetBoundingBox( layer.path )</code></li>
  <li>Set: <code>layer.transform = CGAffineTransformMakeTranslation( CGPathGetBoundingBox( layer.path ).origin.x * -1, // same for y-coord: set it to "-1 * the path's origin</code></li>
  </ol>
  
  <p>This works, but ... lots of 3rd party code assumes that the initial transform for a <code>CALayer</code> is Identity.</p>
  
  <p>It shouldn't be this difficult! Surely there's something I'm doing wrong here?</p>
  
  <p>(I've had one suggestion: "every time you add a path, manually run a custom function to shift all the points by <code>-1 * (top-left-point.x, top-left-point.y)</code>". Again, that works - but it's ridiculously complex)</p>