title: How to set the contentGravity variable of CALayer to 'resizeAspectFill'?
body: <p>I am trying to set the contentGravity variable of a CALayer but I am not quite sure how to do this.  I have tried the following without success:</p>
  
  <pre><code>var layer = CAShapeLayer.init()
  layer.contentGravity = .resizeAspectFill // This is not recognised
  </code></pre>
  
  <p>My UIImageView presents the image taken from the camera of the phone.  I then use the Vision Framework to detect rectangles, which return the four corner coordinates of the detected rectangle.  I then draw the rectangle in the layer of the UIImageView.  The content mode of the UIIMageView is  'Aspect Fill'.  My rectangle is currently misaligned and i think it has to do with the contentGravity of the layer.  Please see image below:</p>
  
  <p>Rectangle drawn into CAShapelayer:</p>
  
  <pre><code>let rec = UIBezierPath.init()
      rec.move(to: CGPoint.init(x: topLeft.x, y: topLeft.y))
      rec.addLine(to: CGPoint.init(x: topRight.x, y: topRight.y))
      rec.addLine(to: CGPoint.init(x: bottomRight.x, y: bottomRight.y))
      rec.addLine(to: CGPoint.init(x: bottomLeft.x, y: bottomLeft.y))
      rec.close()
  
      self.layer.opacity = 0.4
      self.layer.path = rec.cgPath
      self.layer.lineWidth = 5
      self.layer.strokeColor = UIColor.yellow.cgColor
      self.layer.frame = self.imgPreViewOutlet.bounds
  
      self.imgPreViewOutlet.layer.addSublayer(self.layer)
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/wpM3A.png" rel="nofollow noreferrer">image show misaligned rectangle drawn in the layer of UIImageView</a></p>