dimanche 3 juillet 2016

AVCaptureVideoPreviewLayer doesn't take up complete view


I have a storyboard reference to a view called "previewView", it's the view in green.

I am trying to add an AVCaptureVideoPreviewLayer to that view. Though I only get a tiny square for the preview.

enter image description here

Here is the code I use to create the video preview and add it to the view.

 // Initialize the video preview layer and add it as a sublayer to the viewPreview view's layer.
    _videoPreviewLayer = [[AVCaptureVideoPreviewLayer alloc] initWithSession:_captureSession];
    [_videoPreviewLayer setVideoGravity:AVLayerVideoGravityResizeAspectFill];
    [_videoPreviewLayer setFrame:CGRectMake(0, 0, _previewView.frame.size.width, _previewView.frame.size.height)];
    [_previewView.layer addSublayer:_videoPreviewLayer];

On this line

  [_videoPreviewLayer setFrame:_previewView.layer.bounds];

But it too didnt' work.

What am I doing wrong?


Aucun commentaire:

Enregistrer un commentaire