If you are interested in private API, this is how Apple does it:
There is a class named _UISheetDetent
. With this class, you can either create system defined "detents"—medium and large—or provide your own block-based logic (input param is the presentation controller's container view, and the return value is a double—the percent to open the sheet).
You create an array of these "detents" and provide them to the sheet presentation controller using the _setDetents:
method (or setValue:forKey:
). To replicate the share sheet behavior, you need an array with two "detents": medium and large.
There is also the _indexOfLastUndimmedDetent
property, which controls which "detent" starts the dimming process.
I'm not sure why Apple hasn't exposed this as public API. It is concise, simple and works well.
You should probably not use this API, but if you decide to use it, it should be very easy to hide it. In any case, make sure to open a Feedback with Apple to expose this API in a future version of the SDK.
preferredContentSize
you set... if you inspect view hierarchy the root VC on the system share sheet is presented using avc.modalPresentationStyle = .formSheet
, then there's an embedded navVC/activityVC that both are presented with a.pageSheet
style. I can confirm there are no transition or interaction controllers of any kind, and although the system uses a slightly differentUIPresentationController
the values on both are identical.formSheet
has a custompreferredContentSize
and the children ones do not, so I think it only matters on the original presented VC. I tried overridingsize(forChildContentContainer: withParentContainerSize:)
on the view controller presenting the child, and I tried setting thepreferredContentSize
like ALL over the view lifecycle on the child, but although the value can be inspected to exist, it doesn't respect it. Transition style on default + system both default (vertical).preferredContentSize
. While typically used for.popover
style, docs in theory say this should be supported "in some cases" too: developer.apple.com/documentation/uikit/uiviewcontroller/…. Perhaps noodling with some of the other methods in theUIContentContainer
might help? (viewWillTransition(to:with:)
)