AVCaptureVideoPreviewLayer Not Filling Bounds

隐身守侯 提交于 2019-12-07 18:48:23

问题


I have a AVCaptureVideoPreviewLayer and I want to fill that to the bounds of my UIView. It doesn't seem to be working correctly, though. It only shows on around 3/4 of the screen.

CGRect bounds=self.previewView.layer.bounds;
self.previewLayer.videoGravity = AVLayerVideoGravityResizeAspectFill;
self.previewLayer.bounds = bounds;
self.previewLayer.position=CGPointMake(CGRectGetMidX(bounds), CGRectGetMidY(bounds));
[self.previewView.layer addSublayer:self.previewLayer];

Image: http://cl.ly/image/1Y441f3B2d1m


回答1:


It's likely that your container view get's resized at some point after the preview layer has been added to it, and since CALayer's don't have autoresizing masks or autolayout, it doesn't update it's frame, you'll need to do it manually



来源:https://stackoverflow.com/questions/27735187/avcapturevideopreviewlayer-not-filling-bounds

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!