In this blog, we will see UISheetPresentationController. UISheetPresentationController manages the appearance and behavior of the sheet. Using this we can show our viewController as a sheet. In WWDC 2021 with the introduction of iOS 15, Apple also includes improvements to presenting sheets in UIKit with the new UISheetPresentationController.
Let’s see an example of it.
1 2 3 4 5 6 7 8 9 |
func sheet() { let presentingViewController = PresentingViewController() if let sheet = presentingViewController.sheetPresentationController{ sheet.detents = [.medium(), .large()] sheet.largestUndimmedDetentIdentifier = .medium sheet.prefersScrollingExpandsWhenScrolledToEdge = false } present(presentingViewController, animated: true, completion: nil) } |
We have created a function sheet. There we have created an instance of our presenting ViewController. After that, we used the sheetPresentationController property. The detents accept an array. Here we have passed medium and large for the size of our ViewController. We have first used medium so our presenting ViewController will first appear in medium size. We have used the largestUndimmedDetentIdentifier property to add the dimming view. This would make the dimming view go away for a medium detent, and we can interact with the view underneath. We have used prefersScrollingExpandsWhenScrolledToEdge false To make the content scrollable in a medium detent. After that, we presented the view controller with the animated value true and completion nil.
Thanks for reading this blog.
You can also check other blogs from here. If you have any issues, queries, or suggestions then you can leave your issues/queries/suggestions in the comment section.