Search code examples
iosswiftuikituisheetpresentationcontroller

iOS 16: Set Minimum Detent for sheetPresentationController


Is there a way in iOS 16's expanded UISheetPresentationController API to set a minimum detent height for a presented sheet? (i.e. such that it does not dismiss from the screen?)

Example presentation code:

let viewControllerToPresent = UIViewController()
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)

Solution

  • Adding viewControllerToPresent.isModalInPresentation = true as a property enables this experience.