Monday, May 16, 2016

swift iOS hide keyboard away

To hide the keyboard away from screen by tapping other part, we need a command to do that.

By keying in touchesBegan, the IDE will automatically overwrite this
override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) { 
        self.view.endEditing(true
 or
view.endEditing(true)
        
    }

func touchesBegan is called when user tap the screen at outside textboxes.





If you keyboard has a return key and wanted to hide the keyboard after user tap on return key:

 func textFieldShouldReturn(textField: UITextField!) -> Bool {                textBoxField.resignFirstResponder()       
return true    
}
textBoxField is the textbox object

No comments:

Post a Comment