根据https://stackoverflow.com/a/64726641/3286489中的回答,我可以使用UISwipeGestureRecognizer
.
但是,当我将相同的代码传输到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
注意:如果不在全屏模式下,向下滑动以关闭仍然有效。