UISheetPresentationController: Remove Dim Background but Keep Touch-to-Dismiss?

I'm using the UISheetPresentationController to present a view, as shown in the following code:

@IBAction func click(_ sender: Any) {
    let whiteViewController = WhiteViewController.instanceFromMainStoryBoard()
    
    if let sheet = whiteViewController.sheetPresentationController {
        sheet.detents = [.medium()]
        
        sheet.prefersScrollingExpandsWhenScrolledToEdge = false
        
        sheet.prefersGrabberVisible = false
        
        // Remove dim effect.
        ////sheet.largestUndimmedDetentIdentifier = .medium
    }
    
    self.present(whiteViewController, animated: true)
}

The outcome is as follow

This code results in a presentation with:

  1. A dimmed background.
  2. A 'Touch anywhere to dismiss' behavior.

However, I want to remove the dim background while keeping the 'Touch anywhere to dismiss' functionality. When I add the line:

sheet.largestUndimmedDetentIdentifier = .medium

The dim background is indeed removed, but the touch-to-dismiss behavior is gone too, as illustrated:

Is there a way to achieve both – removing the dim background and retaining the touch-to-dismiss functionality?

Thank you.

Replies

There is not a way to remove the dimming view and preserve the touch-to-dismiss functionality. The lack of dimming is meant to convey to the user that the area above the card is interactive.

Why do you want to remove the dimming and preserve touch-to-dismiss?

  • Thank you. This is one of the potential use cases: real-time font changing. The font selection option will be placed within the UISheetPresentationController. By omitting the dim effect, users can accurately view the results of their font selection.

Add a Comment