gpt4 book ai didi

ios - UIGestureRecognizer 仅限于 CGRect

转载 作者:行者123 更新时间:2023-11-30 12:10:35 26 4
gpt4 key购买 nike

我有一个 View ,其中显示一个菜单,其中一个表格具有右侧透明背景以覆盖 View 的其余部分,我可以在点击右侧时隐藏菜单,但随后无法点击表格行。

-框架全屏

self.menuVC.view.frame = CGRect(x: 0, y: 0, width: UIScreen.main.bounds.size.width, height: UIScreen.main.bounds.size.height)
self.menuVC.view.backgroundColor = UIColor.black.withAlphaComponent(0.5)

-手势

        self.tapBackground = UITapGestureRecognizer(target: self, action: #selector(self.hideTapMenu))
self.asda = CGRect(x: self.table.bounds.width, y: 0.0, width: self.view.frame.width, height: self.view.frame.height)
self.view.addGestureRecognizer(self.tapBackground)


self.addChildViewController(self.menuVC)
self.view.addSubview(self.menuVC.view)

隐藏菜单

 func hideTapMenu (gesture: UIGestureRecognizer) {
let p = gesture.location(in: self.view)

if asda.contains(p){
hideMenu()
} else {
print("Touching menu")
}

}


func hideMenu(){

UIView.animate(withDuration: 0.4, animations: { () -> Void in

self.menuVC.view.frame = CGRect(x: -UIScreen.main.bounds.size.width, y: 0, width: UIScreen.main.bounds.size.width, height: UIScreen.main.bounds.size.height)
}) {(finished) in

self.menuVC.view.removeFromSuperview()
}

AppDelegate.isMenuShown = true
}

this is the screen

我可以将 GestureRecognizer 添加到第二个 CGRect 吗?

谢谢!

最佳答案

您可以使用 UIGestureRecognizerDelegate 来简单处理它。在代码中实现其 gestureRecognizer(_:shouldRecognizeSimultaneouslyWith:) 方法以返回 true - 这样您的手势识别器就可以工作,但它也允许识别其他手势。这样 table 的内部手势识别器就应该正常工作。

代码:

// add this to initializing code to set its delegate to self
self.tapBackground.delegate = self

委托(delegate)实现:

extension YourViewController: UIGestureRecognizerDelegate {
func gestureRecognizer(_ gestureRecognizer: UIGestureRecognizer, shouldRecognizeSimultaneouslyWith otherGestureRecognizer: UIGestureRecognizer) -> Bool {
return true
}
}

关于ios - UIGestureRecognizer 仅限于 CGRect,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46115611/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com