在Swift 2.3中关闭UIAlertController键盘

时间:2016-10-29 21:56:50

标签: ios swift keyboard uialertcontroller

我最近升级到最新的Xcode版本并将我的项目转换为Swift 2.3。直到2.2,当我显示UIAlertController时,我用经典

解雇了键盘
override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?){ 
   view.endEditing(true)         
   super.touchesBegan(touches, withEvent: event)
}

嗯,它不再起作用了。试图更改textView的UIKeyboardTypereturnKeyType。没运气。有什么想法吗?

1 个答案:

答案 0 :(得分:0)

尝试为视图使用tapGesture Recognizer。试试这个link

或者您可以试用此代码:

override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?)
{        
super.touchesBegan(touches, withEvent: event)
view.endEditing(true)  
}

希望这会帮助你。快乐的编码