Q:

How to resize a sublayer in view with in Swift?

I have a session with AVfoundation to record a video and take phootos, and this session is necessary add to a view to show this.  I add this with this code:
 var previewLayer: AVCaptureVideoPreviewLayer = AVCaptureVideoPreviewLayer.layerWithSession(self.session) as AVCaptureVideoPreviewLayer

  previewLayer.frame = self.imagePreview.bounds
    self.imagePreview.layer.addSublayer(previewLayer)

imagePreviw is the UIView.
This is adding correctly, but the session camera only show in a part of the view, how can I show this in all view?
I add picture to show the problem and that I want:

A:

I think the frame is correct but I think you should set the videoGravity like this:
previewLayer.videoGravity = AVLayerVideoGravityResizeAspectFill;

