在AVCaptureSession运行时显示摄像机流

Pet*_*ter 10 iphone avfoundation avcapturesession avcapturedevice

根据http://developer.apple.com/iphone/library/qa/qa2010/qa1702.html,我能够使用AVCaptureSession从相机捕获视频帧.但是,似乎AVCaptureScreen从相机捕获帧而不在屏幕上显示相机流.我想像UIImagePicker一样显示相机流,以便用户知道相机正在打开并看到相机指向的位置.任何帮助或指针将不胜感激!

Per*_*ako 19

AVCaptureVideoPreviewLayer正是您所需要的.

Apple用于演示如何使用它的代码片段是:

AVCaptureSession *captureSession = <#Get a capture session#>;
AVCaptureVideoPreviewLayer *previewLayer = [AVCaptureVideoPreviewLayer layerWithSession:captureSession];
UIView *aView = <#The view in which to present the layer#>;
previewLayer.frame = aView.bounds; // Assume you want the preview layer to fill the view.
[aView.layer addSublayer:previewLayer];
Run Code Online (Sandbox Code Playgroud)