Class

AVCaptureVideoPreviewLayer

A Core Animation layer that displays the video as it’s captured.

Declaration

class AVCaptureVideoPreviewLayer : CALayer

Overview

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

You use this preview layer in conjunction with a capture session, as shown in the following code fragment.

// Create a preview layer.
let previewLayer = AVCaptureVideoPreviewLayer()

// Connect the preview layer with the capturing session.
previewLayer.session = captureSession

// Add the preview layer into the view's layer hierarchy.
view.layer.addSublayer(previewLayer)

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 layer displays the video content within its bounds.

var isPreviewing: Bool

A Boolean value that indicates whether the layer is rendering video frames from its source.

Session Configuration

var session: AVCaptureSession?

The previewed capture session.

var connection: AVCaptureConnection?

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

func setSessionWithNoConnection(AVCaptureSession)

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

Converting Between Coordinate Systems

func captureDevicePointConverted(fromLayerPoint: CGPoint) -> CGPoint

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

func layerPointConverted(fromCaptureDevicePoint: CGPoint) -> CGPoint

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

func layerRectConverted(fromMetadataOutputRect: CGRect) -> CGRect

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

func metadataOutputRectConverted(fromLayerRect: CGRect) -> CGRect

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

func transformedMetadataObject(for: AVMetadataObject) -> AVMetadataObject?

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

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.