swiftuiviewcontrolleruikitpresentviewcontroller

Interactive background (presenting) view controller when presenting pageSheet


I'd like to ask you if there is any way to make presenting view controller interactive while presenting pageSheet vc. In the iOS 15 apple introduced detens for pageSheets and when pageSheet is in the .medium() state I'd like to be able to interact with the viewcontroller that's behind that sheet. Is this possible?


Solution

  • You can do that by setting largestUndimmedDetentIdentifier property on UISheetPresentationController Here is an example of presenting medium detend with tappable viewcontroller that is behind the sheet:

    private func presentModal() {
        let storyboard = UIStoryboard(name: "Main", bundle: nil)
        let sheetVC = storyboard.instantiateViewController(withIdentifier: "SheetVC") as! SheetVC
        let nav = UINavigationController(rootViewController: sheetVC)
        // 1
        nav.modalPresentationStyle = .pageSheet
        // 2
        if let sheet = nav.sheetPresentationController {
            
            // 3
            sheet.detents = [.medium(), .large()]
            sheet.largestUndimmedDetentIdentifier = .medium
        }
        // 4
        present(nav, animated: true, completion: nil)
    }
    

    For more info I recommend following article