Wednesday, October 28, 2026
HomeiOS Developmentios - Add dismiss button to Backside Sheet

ios – Add dismiss button to Backside Sheet

[ad_1]

In Apple’s documentation on Sheet Views, they display how you can instantiate a view controller that shows a Backside Sheet with a “shut” button on the right-hand aspect. Think about the picture under:

enter image description here

I’m having a tough time replicating this. Once I current the Sheet View in a NavigationController, and explicitly add a detailed button, I can see the shut button however the sheet turns into a .massive() detent. Their picture suggests they’re reaching this with a .medium() detent. Documentation for UISheetPresentationController reveals no different various. Any thought what I’m doing fallacious?

My SheetController:

override func viewDidLoad() {
    ....
    navigationItem.rightBarButtonItem = UIBarButtonItem.init(barButtonSystemItem: .achieved, goal: self, motion: #selector(closeSheet))
    ....
}

In a unique controller, a button click on initiates the presentation of the sheetController:

@objc func showTheSheet() {
    let updateController = MySheetController()
    if let sheet = updateController.sheetPresentationController {
        sheet.detents = [.medium()]
        sheet.largestUndimmedDetentIdentifier = nil
        sheet.prefersGrabberVisible = true
        sheet.prefersScrollingExpandsWhenScrolledToEdge = true
        sheet.prefersEdgeAttachedInCompactHeight = true
        sheet.widthFollowsPreferredContentSizeWhenEdgeAttached = true
    }
    let navController = UINavigationController(rootViewController: updateController)
    self.current(navController, animated: true, completion: nil)
}

[ad_2]

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments