If you are creating a UISheetPresentationController with custom detents and you have a need to disable one of the detents, then you can do so by returning a special value from the detent's resolver. This is addressed in the Objective-C documentation for customDetentWithIdentifier:resolver:. You return the special value UISheetPresentationControllerDetentInactive.
For example:
UISheetPresentationControllerDetent *customDetent = [UISheetPresentationControllerDetent customDetentWithIdentifier:@"customId" resolver:^CGFloat(id<UISheetPresentationControllerDetentResolutionContext> _Nonnull context) {
if (some condition) {
return UISheetPresentationControllerDetentInactive;
} else {
return context.maximumDetentValue / 3.0;
}
}];
However, if you wish to do this in Swift, there is no corresponding API for UISheetPresentationControllerDetentInactive. It turns out that you can just use .greatestFiniteMagnitude instead.
For example:
let customDetent = UISheetPresentationController.Detent.custom(identifier: .init("customId")) { context in
if some condition {
return .greatestFiniteMagnitude //UISheetPresentationControllerDetentInactive
} else {
return context.maximumDetentValue / 3.0
}
}
It might be tempting to add the following:
extension UISheetPresentationController.Detent {
static let Inactive = CGFloat.greatestFiniteMagnitude
}
but this could cause a conflict if Apple adds a similar API in the future.
This oversight in the Swift API has been reported as FB25567661.