Function

AVMakeRect(aspectRatio:insideRect:)

Returns a scaled CGRect that maintains the specified aspect ratio when within a bounding object.

Declaration

func AVMakeRect(aspectRatio: CGSize, insideRect boundingRect: CGRect) -> CGRect

Parameters

aspectRatio

The width and height ratio (aspect ratio) you want to maintain.

boundingRect

The bounding rectangle you want to fit into.

Return Value

Returns a scaled CGRect that maintains the aspect ratio specified by aspectRatio that fits withinboundingRect.

Discussion

This is useful when attempting to fit the naturalSize property of an AVPlayerItem object within the bounds of another CALayer. You would typically use the return value of this function as an AVPlayerLayer frame property value. For example:

myPlayerLayer.frame = AVMakeRectWithAspectRatioInsideRect(myPlayerItem.naturalSize, mySuperLayer.bounds);

See Also

Configuring Player Layer Values

var player: AVPlayer?

The player for which the player layer displays visual output.

var isReadyForDisplay: Bool

A Boolean value that indicates whether the first video frame has been made ready for display for the current item of the associated player.

var videoGravity: AVLayerVideoGravity

A value that specifies how the video is displayed within a player layer’s bounds.

struct AVLayerVideoGravity

A value that defines how the video is displayed within a layer’s bounds rectangle.

var videoRect: CGRect

The current size and position of the video image as displayed within the receiver's bounds.

var pixelBufferAttributes: [String : Any]?

The client requirements for the visual output displayed in the player layer during playback.