Reputation: 2738
I am trying to add a AVCaptureVideoPreviewLayer into my view like this
[captureVideoPreviewLayer setFrame:CGRectMake(10.0f,10.0f,300.0f,300.0f)];
[self.view.layer addSublayer:captureVideoPreviewLayer];
but it doesnt seem to follow the CGRectMake, the layer is 300 in height but not in width, I am not sure why!
Upvotes: 3
Views: 2171
Reputation: 2738
The solution was simple, I just had to add captureVideoPreviewLayer.videoGravity = AVLayerVideoGravityResizeAspectFill;
and that fixed the problem.
Upvotes: 11
Reputation: 12671
Make sure you are assigning a view outlet to captureVideoPreviewLayer
, better to access like self.captureVideoPreviewLayer
.
If you are doing things in order then setting the frame should work using CGRectMake
. I have been using it to change the size of preview layer like this.
self.captureVideoPreviewLayer.frame = CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height);
Upvotes: 0
Reputation: 532
It seems, as if your view has the wrong dimension for the layer. For this update the size of the view at least to the desired rect:
[self.view setBounds:CGRectMake(10.0f,10.0f,300.0f,300.0f)];
Upvotes: 0