AVCam not in fullscreen

2019-03-27 13:24发布

I've integrated AVCam in my iOS app. The problem is in iPhone 4 the preview frame isn't fullscreen, it has empty side borders...

How can I solve this?

Thanks.

2条回答
唯我独甜
2楼-- · 2019-03-27 13:31

Fixed it with the following method in AVCamPreviewView.

- (void)setSession:(AVCaptureSession *)session {
    ((AVPlayerLayer *)[self layer]).videoGravity = AVLayerVideoGravityResizeAspectFill;
    ((AVPlayerLayer *)[self layer]).bounds = ((AVPlayerLayer *)[self layer]).bounds;
    [(AVCaptureVideoPreviewLayer *)[self layer] setSession:session];
}
查看更多
我只想做你的唯一
3楼-- · 2019-03-27 13:33

You need to use the videoGravity property of the AVCaptureVideoPreviewLayer.

Take a look to the doc. You need to use: AVLayerVideoGravityResizeAspectFill

Edit:

Based on that the solution founded by the asker is:

- (void)setSession:(AVCaptureSession *)session {
    ((AVPlayerLayer *)[self layer]).videoGravity = AVLayerVideoGravityResizeAspectFill;
    ((AVPlayerLayer *)[self layer]).bounds = ((AVPlayerLayer *)[self layer]).bounds;
    [(AVCaptureVideoPreviewLayer *)[self layer] setSession:session];
}
查看更多
登录 后发表回答