ios - 当用户触摸屏幕的特定部分时如何触发事件 - ios?
问题描述
我有一个使用 UIViewController 制作的自定义弹出窗口(演示文稿:'over current context') - 请参见下文。我想做的是一旦用户触摸屏幕的顶部 - 黑暗的一半,它不包含菜单选项,就会关闭 UIViewController 。我可以触发什么事件来让它工作?
解决方案
您可以将轻击手势添加到 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?)
推荐阅读
- javascript - Javascript - 如何在第一列中写入每个 % 2 === 0 否则为 2cnd 列
- python - 如何将删除请求重定向到 django rest 框架中的特定 url?
- spring-boot - ibm mq 消费者的连续连接重试尝试导致一段时间后内存泄漏导致 jvm 崩溃。如何解决这个问题?
- ios - Unable to simultaneously satisfy constraints. Probably at least one of the constraints
- android - 如何避免 listview android 应用程序崩溃
- python - Numba,Numpy:在并行 @jit 函数中调用 @guvectorized 函数
- node.js - 在 systemctl 服务文件中从 ExecStart 运行 npm start
- c# - 如何在 Rx.Net 中实现排气映射处理程序?
- entity-relationship - 有什么方法可以自动将 EER - 模型转换为维度模型?
- reactjs - react如何改变react数组中对象的值