I am presenting a layover VC programmatically.
However, I would like to keep the swipe down functionality of dismissing the VC and keep the background blur while ultimately presenting the VC half way from the bottom of view.
Presenting VC:
let navVC = UINavigationController(rootViewController: SnackBarViewController())
present(navVC, animated: true)
I have found a way to present the VC half way like so, but I lose the swipe functionality and the background blur.
let navVC = UINavigationController(rootViewController: SnackBarViewController())
navVC.transitioningDelegate = self
navVC.modalPresentationStyle = .custom
present(navVC, animated: true)
extension SettingsViewController : UIViewControllerTransitioningDelegate {
func presentationController(forPresented presented: UIViewController, presenting: UIViewController?, source: UIViewController) -> UIPresentationController? {
return HalfSizePresentationController(presentedViewController: presented, presenting: presenting)
}
}
class HalfSizePresentationController : UIPresentationController {
override var frameOfPresentedViewInContainerView: CGRect {
get {
guard let theView = containerView else {
return CGRect.zero
}
return CGRect(x: 0, y: theView.bounds.height/2, width: theView.bounds.width, height: theView.bounds.height/2)
}
}
}
Is there a better way to present the VC half way in swift 5 without losing the presentation style format by default?
I have also heard of UISheetPresentationController
using detents
but im not entirely sure how to implement.
base ios version 13.0. xcode version 12.5.1