我有一个使用UIViewController创建的自定义弹出窗口(演示:“在当前上下文中”)-请参见下文。我想做的是,一旦用户触摸屏幕的顶部(不包含菜单选项)的上半部分,则将UIViewController关闭。我可以触发什么事件才能使其正常工作?
答案 0 :(得分:1)
您可以向darkView添加轻击手势,并在其内部添加
let tapGesture = UITapGestureRecognizer(target: self, action: #selector(handleTap(_:)))
mydarkView.addGestureRecognizer(tapGesture)
//
// 3. this method is called when a tap is recognized
@objc func handleTap(_ sender: UITapGestureRecognizer) {
self.dismiss(animated:true,completion:true)
}
或使用
override func touchesBegan(_ touches: Set<UITouch>,
with event: UIEvent?)