Last active
April 15, 2022 21:08
-
-
Save konnnn/1f280f256a0c21a4d5119424c258722f to your computer and use it in GitHub Desktop.
Present a ViewController on Half screen
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// iOS 15 and above | |
func presentSecondViewController() { | |
guard let secondViewController = self.storyboard?.instantiateViewController(withIdentifier: "SecondViewController") as? SecondViewController else { return } | |
secondViewController.providesPresentationContextTransitionStyle = true | |
secondViewController.definesPresentationContext = true | |
secondViewController.modalPresentationStyle = .formSheet // The presentation style for modal view controllers | |
secondViewController.isModalInPresentation = true // Cancels dismiss the viewController by swiping down | |
secondViewController.modalTransitionStyle = .coverVertical // The transition style to use when presenting the view controller | |
if let presentationViewController = secondViewController.presentationController as? UISheetPresentationController { | |
presentationViewController.detents = [.medium()] // change to [.medium(), .large()] for a half *and* full screen sheet | |
presentationViewController.preferredCornerRadius = 42.0 | |
} | |
self.present(secondViewController, animated: true, completion: nil) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Half-screen sheet / .detents = [.medium()]
https://i.stack.imgur.com/Siycc.gif
Half and full-screen sheet / .detents = [.medium(), .large()]
https://i.stack.imgur.com/DHGCk.gif