问题
With the new default card modal presentation in iOS 13, there is a nice feature that is swipe to dismiss. Is it possible to use this feature while presenting a classic .fullscreen
modal?
I checked and if isModalInPresentation
is false while presenting in fullscreen.
Any ideas?
回答1:
It seems that the swipe to dismiss will only work if the modal is presented as a sheet, as stated in this year's wwdc:
Now, what do you all have to do to support Pull to Dismiss? In general, nothing. If you present something as a Sheet, the ability to pull it down comes for free.
And it makes sense. When you present it as a sheet, the UI makes it look like you can swipe the modal down. When you present it on fullscreen, it would not be intuitive for the user that he should swipe the page down to dismiss. I'd rather use a button on this case.
回答2:
As @pepsy said, the full screen view is not intended to be dismissed by swiping. However, if you still want to try it, here's something I started
NOTE: it's a bit glitchy the parent controller is not visible while dragging.
I added a UIPanGestureRecognizer to the view to simulate the swipe to dismiss behavior. I also have a Close (X) button, as the swipe gesture is not as intuitive as for a sheet.
@IBAction func panGestureRecognizerHandler(_ sender: UIPanGestureRecognizer) {
let translationY = sender.translation(in: sender.view!).y
switch sender.state {
case .began:
break
case .changed:
view.transform = CGAffineTransform(translationX: 0, y: translationY)
case .ended, .cancelled:
if translationY > 160 {
dismiss(animated: true, completion: nil)
} else {
UIView.animate(withDuration: 0.2, animations: {
self.view.transform = CGAffineTransform(translationX: 0, y: 0)
})
}
case .failed, .possible:
break
@unknown default:
break
}
}
来源:https://stackoverflow.com/questions/57803695/is-it-possible-to-use-swipe-to-dismiss-while-presenting-a-fullscreen-modal-in-io