我以前用过这个。
override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?)
{
self.view.endEditing(true)
}
但是现在在 Xcode 8 beta 中我得到这个错误:
声明 touchBegan(touches:withEvent)
具有与任何潜在覆盖不同的参数名称。
有什么想法吗?
最佳答案
这对我有用:
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
self.view.endEditing(true)
}
请注意函数参数中非常微妙的 Swift 3 更新。在 The Swift Programming Language (Swift 3) 的第 20 和 21 页上,他们解释说:
“By default, functions use their parameter names as labels for their arguments. Write a custom argument label before the parameter name, or write _ to use no argument label.”
:)
关于ios - Xcode 8 - 当用户点击背景时让键盘消失,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37895032/