Protocol

UIContentContainer

A collection of methods that help you adapt the contents of your view controllers to size and trait changes.

Overview

All UIViewController and UIPresentationController objects provide default implementations for the methods of this protocol. When creating your own custom view controller or presentation controller, you can override the default implementations to make adjustments to your content. For example, you might use these methods to adjust the size or position of any child view controllers.

When overriding the methods of this protocol, you should generally call super to give UIKit a chance to perform any default behaviors. View controllers and presentation controllers perform their own adjustments when these methods are called. Calling super ensures that UIKit is able to continue making the changes it needs to adapt your interface to changes.

Topics

Responding to Environment Changes

func viewWillTransition(to: CGSize, with: UIViewControllerTransitionCoordinator)

Notifies the container that the size of its view is about to change.

Required.

func willTransition(to: UITraitCollection, with: UIViewControllerTransitionCoordinator)

Notifies the container that its trait collection changed.

Required.

Responding to Changes in Child View Controllers

func size(forChildContentContainer: UIContentContainer, withParentContainerSize: CGSize)

Returns the size of the specified child view controller’s content.

Required.

func preferredContentSizeDidChange(forChildContentContainer: UIContentContainer)

Notifies an interested controller that the preferred content size of one of its children changed.

Required.

func systemLayoutFittingSizeDidChange(forChildContentContainer: UIContentContainer)

Notifies the container that a child view controller was resized using auto layout.

Required.

var preferredContentSize: CGSize

The preferred size for the container’s content.

Required.

Relationships

Inherits From

See Also

First Steps

class UIViewController

Provides the infrastructure for managing the views of your UIKit app.

class UIPresentationController

An object that provides advanced view and transition management for presented view controllers.