PreviewCropController

@objcMembers
public class PreviewCropController : UIViewController

The PreviewCropController handles cropping for media in the LibraryController.

Figure 1 Preview crop controller

Preview crop controller

The crop controller can be accessed with the following:

let cropController = containerController.libraryController.previewCropController

The below examples demonstrate a few custom variations in cropping behavior.

Allow only content of a specific aspect ratio. For example square content only:

cropController.aspectRatio = CGSize(width: 1, height: 1)

Allow only content of a maximum aspect ratio. This is the default functionality.

cropController.maxRatioForPortraitMedia = CGSize(width: 3, height: 4)
cropController.maxRatioForLandscapeMedia = CGSize(width: 16, height: 9)

Set content initially zoomed in or out. For example initially zoomed out:

cropController.defaultsToAspectFillForPortraitMedia = false
cropController.defaultsToAspectFillForLandscapeMedia = false

Apply no initial cropping, unless the user interacts with the cropper:

cropController.maxRatioForPortraitMedia = CGSize(width: 1, height: .max)
cropController.maxRatioForLandscapeMedia = CGSize(width: .max, height: 1)

cropController.defaultsToAspectFillForPortraitMedia = false
cropController.defaultsToAspectFillForLandscapeMedia = false

Disable cropping from user interaction:

cropController.userInteractionEnabled = false

If the last two examples are combined, cropping will be disabled entirely.

Initial Layout

  • If this is true when portrait media is loaded into the crop controller, the media will by default be zoomed in to fill the crop controller and if false it will by default be zoomed out.

    Setting this to true will bias the user to produce square content and false will bias them to produce portrait content.

    If media has already loaded in, you must call layoutMedia() after setting this for an immediate effect.

    Attention

    This variable has no effect if aspectRatio is set.

    Default value: true

    Declaration

    Swift

    public var defaultsToAspectFillForPortraitMedia: Bool
  • If this is true when landscape media is loaded into the crop controller, the media will by default be zoomed in to fill the crop controller and if false it will by default be zoomed out.

    Setting this to true will bias the user to produce square content and false will bias them to produce landscape content.

    If media has already loaded in, you must call layoutMedia() after setting this for an immediate effect.

    Attention

    This variable has no effect if aspectRatio is set.

    Default value: true

    Declaration

    Swift

    public var defaultsToAspectFillForLandscapeMedia: Bool

Grid Lines

  • This controls when the grid lines in the crop controller should appear.

    Default value: .interaction

    Declaration

    Swift

    public var gridLinesMode: GridLinesMode { get set }
  • Call this function if you want to briefly flash the grid lines.

    Declaration

    Swift

    @objc
    public func flashGridLines()

Controlling Content Ratio

  • Set this if you want to force the crop controller to use a specific aspect ratio. This will hide the zoom button when set.

    For example square: CGSize(width: 1, height: 1)

    Or the same ratio as 1080p video: CGSize(width: 1920, height: 1080) or CGSize(width: 16, height: 9)

    If media has already loaded in, you must call layoutMedia() after setting this for an immediate effect.

    Default value: nil

    Declaration

    Swift

    public var aspectRatio: CGSize?
  • This ratio is the maximum amount of content that can be visible when portrait media is zoomed all the way out.

    If media has already loaded in, you must call layoutMedia() after setting this for an immediate effect.

    Attention

    This variable has no effect if aspectRatio is set.

    Precondition

    Size width must be less than size height.

    Default value: CGSize(width: 3, height: 4)

    Declaration

    Swift

    public var maxRatioForPortraitMedia: CGSize { get set }
  • This ratio is the maximum amount of content that can be visible when landscape media is zoomed all the way out.

    If media has already loaded in, you must call layoutMedia() after setting this for an immediate effect.

    Attention

    This variable has no effect if aspectRatio is set.

    Precondition

    Size width must be greater than size height.

    Default value: CGSize(width: 16, height: 9)

    Declaration

    Swift

    public var maxRatioForLandscapeMedia: CGSize { get set }

User Interaction

  • Controls whether cropping is enabled.

    Default: true

    Declaration

    Swift

    public var userInteractionEnabled: Bool { get set }
  • Controls whether video media should be paused when the user is dragging it in the crop controller.

    Default value: true

    Declaration

    Swift

    public var pausesVideoOnDrag: Bool

Media Layout

  • This will layout the media again and reset its position.

    Declaration

    Swift

    public func layoutMedia()