Class

AVCaptureVideoPreviewLayer

A Core Animation layer that can display video as it is being captured.

Overview

AVCaptureVideoPreviewLayer is a subclass of CALayer that you use to display video as it is being captured by an input device.

You use this preview layer in conjunction with an AV capture session, as illustrated in the following code fragment:

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];

You use the videoGravity property to influence how content is viewed relative to the layer bounds. On some hardware configurations, you can manipulate the orientation of the layer using orientation and mirrored.

Topics

Creating a Preview Layer

init(session: AVCaptureSession)

Initializes a preview layer with a given capture session.

init(sessionWithNoConnection: AVCaptureSession)

Initializes a preview layer using a given capture session but without making any connections.

Layer Configuration

var videoGravity: AVLayerVideoGravity

Indicates how the video is displayed within a player layer’s bounds rect.

Configuration

var connection: AVCaptureConnection?

The capture connection describing the AVCaptureInputPort to which the preview layer is connected.

var session: AVCaptureSession?

The capture session instance being previewed.

func setSessionWithNoConnection(AVCaptureSession)

Attaches the receiver to a given session without implicitly forming a connection.

Converting Between Coordinate Systems

func captureDevicePointConverted(fromLayerPoint: CGPoint)

Converts a point from layer coordinates to the coordinate space of the capture device.

func layerPointConverted(fromCaptureDevicePoint: CGPoint)

Converts a point from the coordinate space of the capture device to the coordinate space of the layer.

func transformedMetadataObject(for: AVMetadataObject)

Converts a metadata object’s visual properties to layer coordinates.

func metadataOutputRectConverted(fromLayerRect: CGRect)

Converts a rectangle in the preview layer’s coordinate system to one in the coordinate system used for metadata outputs.

func layerRectConverted(fromMetadataOutputRect: CGRect)

Converts a rectangle in the coordinate system used for metadata outputs to one in the preview layer’s coordinate system.

Relationships

Inherits From

Conforms To

See Also

Media Capture Preview

class AVCaptureAudioPreviewOutput

A capture output that provides preview playback for audio being recorded in a capture session.