UISwipeGestureRecognizer是否可以在UIHostingController中查看?

时间:2020-11-08 09:51:16

标签: ios swift swiftui uiswipegesturerecognizer uihostingcontroller

根据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不在全屏模式下,向下滑动即可关闭。

0 个答案:

没有答案