UISheetPresentationController
A presentation controller that manages the appearance and behavior of a sheet.
Declaration
@MainActor class UISheetPresentationControllerOverview
UISheetPresentationController lets you present your view controller as a sheet. Before you present your view controller, configure the sheet presentation controller in its sheetPresentationController property with the behavior and appearance you want for your sheet.
// In a subclass of UIViewController, customize and present the sheet.
func showMyViewControllerInACustomizedSheet() {
let viewControllerToPresent = MyViewController()
if let sheet = viewControllerToPresent.sheetPresentationController {
sheet.detents = [.medium(), .large()]
sheet.largestUndimmedDetentIdentifier = .medium
sheet.prefersScrollingExpandsWhenScrolledToEdge = false
sheet.prefersEdgeAttachedInCompactHeight = true
sheet.widthFollowsPreferredContentSizeWhenEdgeAttached = true
}
present(viewControllerToPresent, animated: true, completion: nil)
}Sheet presentation controllers specify a sheet’s size based on a detent, a height where a sheet naturally rests. Detents allow a sheet to resize from one edge of its fully expanded frame while the other three edges remain fixed. You specify the detents that a sheet supports using detents, and monitor its most recently selected detent using selectedDetentIdentifier.
Topics
Specifying the height
Managing the delegate
Managing user interaction
Managing the appearance
prefersGrabberVisibleprefersPageSizingprefersEdgeAttachedInCompactHeightwidthFollowsPreferredContentSizeWhenEdgeAttachedpreferredCornerRadius