iOS Developer Library

Developer

AVFoundation Framework Reference AV Foundation Functions Reference

Options
Deployment Target:

On This Page
Language:

AV Foundation Functions Reference

Inheritance


Not Applicable

Conforms To


Not Applicable

Import Statement


Swift

import AVFoundation

Objective-C

@import AVFoundation;

This chapter describes the function defined in the AVFoundation Framework.

Functions

  • Returns a scaled CGRect that maintains the aspect ratio specified by a CGSize within a bounding CGRect.

    Declaration

    Swift

    func AVMakeRectWithAspectRatioInsideRect(_ aspectRatio: CGSize, _ boundingRect: CGRect) -> CGRect

    Objective-C

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

    Import Statement

    Objective-C

    @import AVFoundation;

    Swift

    import AVFoundation

    Availability

    Available in iOS 4.0 and later.