I am currently using the UISheetPresentationController
in UIKit to show a sheet on top of a UIViewController
to give additional information about the underlying UIViewController
. The sheet will not block the interaction or dim the underlying UIViewController
. The presented UISheetPresentationController
will have a UICollectionView
with multiple sections to display the additional information.
I would like to have a similar implementation like Apple Maps where the height of the smallest detent is aligned with the actual content of the presented sheet: Apple Maps Sheet displaying exactly the search bar
The smaller custom detent should have the same height than the first section of the UICollectionView
in the presented sheet. Since the underlying view is a different UIViewController
than the presented sheet it is difficult to create a custom detent that is exactly the same height as the content of the first section and would respond to any dynamic view changes.
The simplest solution that I came up with is to use a constant value for the detent height (e.g. 100) and then also use this constant value as a height restriction of the first section in the UICollectionView
in the presented sheet. But using constant height variables could introduce issues when using a different font size and could therefore break the content of the first section of the UICollectionView
. I would be interested if there is a better approach than manually aligning the heights of the sheet detent and the content of the sheet or if there are any best practices to achieve a similar behaviour like in Apple Maps.