Why this happens
Apple Maps introduced a distinctive bottom sheet that users can drag between collapsed, medium, and expanded states. Before iOS 15, UIKit provided no native API for this pattern, so developers built custom solutions using child view controllers, manual frame animation, and pan gesture handling. iOS 15 added UISheetPresentationController, a first-class API that handles detents, backdrop dimming, and gesture coordination automatically.
If you target iOS 15 or later, the native sheet controller is the right choice. It respects safe areas, works with navigation stacks, and requires far less code. For apps that must support iOS 14 or earlier, a custom implementation remains necessary.
How to fix it
1. Use UISheetPresentationController (iOS 15+) — Modern native approach
This is the simplest and most maintainable solution. Configure the presented view controller’s sheetPresentationController before presenting.
import UIKit
final class MapViewController: UIViewController {
func presentBottomSheet() {
let sheetVC = BottomSheetViewController()
if let sheet = sheetVC.sheetPresentationController {
sheet.detents = [.medium(), .large()]
sheet.prefersGrabberVisible = true
sheet.preferredCornerRadius = 24
}
present(sheetVC, animated: true)
}
}
Key properties
– detents: Array of UISheetPresentationController.Detent (.medium(), .large(), or custom).
– prefersGrabberVisible: Shows the drag indicator.
– preferredCornerRadius: Rounds the top corners.
– largestUndimmedDetentIdentifier: Keeps content behind the sheet interactive at a given detent.
To push additional view controllers inside the sheet while keeping the sheet open, present the next controller with .overCurrentContext:
let detailVC = DetailViewController()
detailVC.modalPresentationStyle = .overCurrentContext
sheetVC.present(detailVC, animated: true)
2. Custom implementation for iOS 14 and earlier — Legacy approach
When you cannot use the native API, replicate the behavior with a child view controller and a pan gesture.
Step 1 — Add the bottom sheet as a child
func addBottomSheet() {
let sheetVC = BottomSheetViewController()
addChild(sheetVC)
view.addSubview(sheetVC.view)
sheetVC.didMove(toParent: self)
let height = view.bounds.height
let width = view.bounds.width
// Start fully off-screen
sheetVC.view.frame = CGRect(x: 0, y: height, width: width, height: height)
self.bottomSheetVC = sheetVC // retain reference
}
Call this in viewDidAppear so the parent’s layout is settled.
Step 2 — Animate the sheet into view
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
UIView.animate(withDuration: 0.3) {
let y = UIScreen.main.bounds.height - 200 // collapsed height
self.bottomSheetVC?.view.frame.origin.y = y
}
}
Step 3 — Handle dragging with a pan gesture
class BottomSheetViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
view.backgroundColor = .clear
let pan = UIPanGestureRecognizer(target: self, action: #selector(handlePan(_:)))
pan.delegate = self
view.addGestureRecognizer(pan)
}
@objc func handlePan(_ recognizer: UIPanGestureRecognizer) {
let translation = recognizer.translation(in: view)
var newY = view.frame.minY + translation.y
// Clamp between collapsed and fully expanded
let minY: CGFloat = 0
let maxY = UIScreen.main.bounds.height - 200
newY = min(max(newY, minY), maxY)
view.frame.origin.y = newY
recognizer.setTranslation(.zero, in: view)
}
}
Step 4 — Coordinate with internal scroll views
If the sheet contains a UIScrollView (or UITableView/UICollectionView), implement UIGestureRecognizerDelegate so the pan gesture and scroll view don’t fight:
extension BottomSheetViewController: UIGestureRecognizerDelegate {
func gestureRecognizer(_ gestureRecognizer: UIGestureRecognizer,
shouldRecognizeSimultaneouslyWith other: UIGestureRecognizer) -> Bool {
guard let scrollView = other.view as? UIScrollView else { return false }
// Allow simultaneous recognition only when sheet is fully expanded
// and scroll view is at top while user drags down
let isAtTop = scrollView.contentOffset.y <= 0
let draggingDown = gestureRecognizer.velocity(in: view).y > 0
let fullyExpanded = view.frame.minY == 0
return fullyExpanded && isAtTop && draggingDown
}
}
Disable the scroll view’s isScrollEnabled when the sheet is partially visible to avoid conflicting gestures.
How to prevent it
- Adopt
UISheetPresentationControlleras soon as your minimum deployment target reaches iOS 15. - Keep the custom implementation isolated in a dedicated class so it can be swapped out.
- Test on multiple screen sizes (iPhone SE to iPhone Pro Max) to verify clamping logic.
- Use Auto Layout inside the sheet’s content view; avoid hard-coded frames for subviews.
- Provide a grabber affordance (the native API does this automatically).
FAQ
What is the minimum iOS version for UISheetPresentationController?
UISheetPresentationController is available starting with iOS 15.0. On earlier versions the property exists but returns nil, so guard with if let sheet = vc.sheetPresentationController.
Can I define custom detent heights?
Yes. Create a UISheetPresentationController.Detent with a custom identifier and implement sheetPresentationController(_:heightForDetent:) in your presented view controller (adopting UISheetPresentationControllerDelegate).
How do I prevent the sheet from dismissing when the user drags down from the medium detent?
Set sheet.prefersScrollingExpandsWhenScrolledToEdge = false and ensure your content view controller returns false from presentationControllerShouldDismiss(_:) when at the medium detent. The native controller handles this automatically when multiple detents are provided.
Image query
iPhone bottom sheet map app
Parts of this guide are adapted from content licensed under CC BY-SA 4.0; this article is shared under the same license.
