【问题标题】:How to trigger an event when a user touches specific part of the screen - ios?当用户触摸屏幕的特定部分时如何触发事件 - ios?
【发布时间】:2018-09-07 19:17:51
【问题描述】:

我有一个使用 UIViewController 制作的自定义弹出窗口(演示文稿:'over current context') - 请参见下文。我想做的是一旦用户触摸屏幕的顶部 - 黑暗的一半,它不包含菜单选项,就会关闭 UIViewController 。我可以触发什么事件来让它工作?

【问题讨论】:

标签: ios swift


【解决方案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?)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-04-09
    • 2012-10-01
    • 1970-01-01
    • 2020-11-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多