Function

AVMakeRectWithAspectRatioInsideRect

Returns a scaled rectangle that maintains the specified aspect ratio within a bounding rectangle.

Declaration

CGRect AVMakeRectWithAspectRatioInsideRect(CGSize aspectRatio, CGRect boundingRect);

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 within boundingRect.

Discussion

Use this function when attempting to fit the presentation size of a player item object’s content within the bounds of another CALayer. Use the returned CGRect as the player layer’s frame property value. For example:

CGSize aspectRatio = CGSizeMake(1920, 1080);
self.playerLayer.frame = AVMakeRectWithAspectRatioInsideRect(aspectRatio, self.superLayer.bounds);

See Also

Configuring Player Layer Values

player

The player for which the player layer displays visual output.

readyForDisplay

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

videoGravity

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

AVLayerVideoGravity

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

videoRect

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

pixelBufferAttributes

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