0

I recently upgraded to latest Xcode version and converted my project to Swift 2.3. Until 2.2, when I displayed an UIAlertController I dismissed the keyboard with the classic

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

Well, it doesn't work anymore. Tried to change textView's UIKeyboardType and returnKeyType. No luck. Any thoughts?

Md. Ibrahim Hassan
  • 5,359
  • 1
  • 25
  • 45
  • 1
    Have you checked this? http://stackoverflow.com/q/26161796/1689376 – alexburtnik Oct 29 '16 at 22:02
  • when alert is presented `touchesBegan` is not fired as alert's background view overlaps your complete self.view. It works with keyboard because keyboard is half presented. – Rajan Maheshwari Oct 30 '16 at 11:03
  • alexburtnik: Thanks for the link. Rajan Maheshwari: you are right. My UIAlertController was too big and its controls were hidden by the keyboard "predictive" mode. I shrinked it and it worked fine. Thanks. – Felipe Andai Oct 30 '16 at 15:32
  • Try out this [link](http://stackoverflow.com/questions/24126678/close-ios-keyboard-by-touching-anywhere-using-swift) Hope this helps you out. Happy coding – Md. Ibrahim Hassan Nov 01 '16 at 07:19

1 Answers1

0

Try to use a tapGesture Recognizer for the View. Try out this link

Or you can try out this Code:

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

Hope this helps you out. Happy coding

Community
  • 1
  • 1
Md. Ibrahim Hassan
  • 5,359
  • 1
  • 25
  • 45