As per answer in https://stackoverflow.com/a/64726641/3286489, I can perform a swipe down to dismiss a fullscreen ViewController using UISwipeGestureRecognizer
.
However, when I transfer the same code to UIHostingController
as below, it doesn't work anymore
class ContextViewController: UIHostingController<CustomDrawViewWrapper> {
let drawViewWrapper: CustomDrawViewWrapper
init(drawView: CustomDrawView) {
self.drawViewWrapper = CustomDrawViewWrapper(drawView: drawView)
super.init(rootView: self.drawViewWrapper)
}
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
override func viewDidLoad() {
super.viewDidLoad()
view.isUserInteractionEnabled = true
let gesture = UISwipeGestureRecognizer(target: self, action: #selector(dismissVC))
gesture.direction = .down
view.addGestureRecognizer(gesture)
}
@objc
private func dismissVC() {
dismiss(animated: true)
}
}
Anything I need to do to get the swipe down working for UIHostingController
?
Note: the swipe down to dismiss still work if the UIHostingController
is not in fullscreen mode.