根据https://stackoverflow.com/a/64726641/3286489中的答案,我可以向下滑动以使用UISwipeGestureRecognizer
关闭全屏ViewController。
但是,当我将相同的代码如下传输到UIHostingController
时,它不再起作用
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)
}
}
为使UIHostingController
正常工作,我需要做些什么吗?
请注意:如果UIHostingController
不在全屏模式下,向下滑动即可关闭。