Is it possible to use swipe to dismiss while presenting a fullscreen modal in iOS 13?

时光怂恿深爱的人放手 提交于 2020-12-12 12:09:20

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!