Reputation: 228
I need to present VC in full screen, but with ability to swipe it down as it was popover, similar to how it works in Apple Music in song details.
I've tried every option in vc.modalPresentationStyle, but it's either in full screen without ability to swipe down to close or with this ability, but not in full screen
vc.modalPresentationStyle = .overFullScreen
vc.modalTransitionStyle = .coverVertical
Upvotes: 1
Views: 4196
Reputation: 228
So, I just presented it in full screen and wrote function, which allows pan to close vc, with decreasing alpha
func panToCloseGesture() {
let panGesture = UIPanGestureRecognizer(target: self, action: #selector(handlePanGesture(_:)))
view.addGestureRecognizer(panGesture)
}
@objc func handlePanGesture(_ sender: UIPanGestureRecognizer) {
let percentThreshold:CGFloat = 0.3
let translation = sender.translation(in: view)
let newY = self.ensureRange(value: view.frame.minY + translation.y, minimum: 0, maximum: view.frame.maxY)
let progress = self.progressAlongAxis(newY, view.bounds.height)
view.frame.origin.y = newY
if newY > 0 {
self.rootView.alpha = 1 - (newY / 400)
}
if sender.state == .ended {
let velocity = sender.velocity(in: view)
if velocity.y >= 1000 || progress > percentThreshold {
self.dismiss(animated: true, completion: nil)
} else {
UIView.animate(withDuration: 0.2, animations: {
self.rootView.alpha = 1
self.view.frame.origin.y = 0
})
}
}
sender.setTranslation(.zero, in: view)
}
Upvotes: -1
Reputation: 51
modalPresentationStyle
:viewController.modalPresentationStyle = .formSheet
preferredContentSize
:viewController.preferredContentSize = CGSize(width: kScreenWidth, height: kScreenHeight)
Upvotes: 1
Reputation: 27
You can try this:
viewController.modalPresentationStyle = .fullScreen
Upvotes: 0