0

I have a detent set in my VC, as a swip-panel on another ViewController (anotherVC) and in certain situations I want to freeze \ disable it from moving up and down...

func viewDidLoad() {
    if let sheet = anotherVC.sheetPresentationController {
           sheet.detents = [.medium(), .large()]
           sheet.delegate = self
           sheet.prefersScrollingExpandsWhenScrolledToEdge = false
           sheet.prefersGrabberVisible = true

           self.present(anotherVC, animated: true)
    }
}

HOW DO I DISABLE THE DETENT FROM MOVING (up and down)?

Aviram Netanel
  • 12,633
  • 9
  • 45
  • 69

1 Answers1

0

In order to prevent the vc / sheet (with the detent) from disappearing & closing, set the isModalInPresentation property to TRUE.

In order to prevent the detent from moving to different sizes, make sure there's only one detent in the array.

here is the code:

if let sheet = anotherVC.sheetPresentationController {
    //only 1 detent in the array:
    sheet.detents = [.medium()]

    //prevents from the mini-view to close:
    sheet.presentedViewController.isModalInPresentation = true
}
Aviram Netanel
  • 12,633
  • 9
  • 45
  • 69