AVCaptureVideoPreviewLayer更改为AspectFill

时间:2015-05-31 19:11:54

标签: ios objective-c avplayer gravity bounds

我希望我的Session能够在我的AVCamPreviewLayer内以aspectFill方式显示。虽然下面的代码就是这样,但它填满了整个屏幕,而不仅仅是预览层连接到故事板上的视图。因此,在更改AVCaptureVideoPreviewLayer时,我希望以某种方式将previewView填充到gravity的界限而不是全屏。

  [(AVCaptureVideoPreviewLayer *)[[self previewView] layer] setVideoGravity:AVLayerVideoGravityResizeAspectFill];

我也试过

- (void)setSession:(AVCaptureSession *)session
{
    ((AVPlayerLayer *)[self layer]).videoGravity = AVLayerVideoGravityResizeAspectFill;
    ((AVPlayerLayer *)[self layer]).bounds = ((AVPlayerLayer *)[self layer]).bounds;
    [(AVCaptureVideoPreviewLayer *)[self layer] setSession:session];
}

**请注意,这确实来自Apple Docs

0 个答案:

没有答案