How to get height of Keyboard?

Swift You can get the keyboard height by subscribing to the UIKeyboardWillShowNotification notification. (Assuming you want to know what the height will be before it’s shown). Swift 4 NotificationCenter.default.addObserver( self, selector: #selector(keyboardWillShow), name: UIResponder.keyboardWillShowNotification, object: nil ) @objc func keyboardWillShow(_ notification: Notification) { if let keyboardFrame: NSValue = notification.userInfo?[UIResponder.keyboardFrameEndUserInfoKey] as? NSValue { let keyboardRectangle = … Read more

Close iOS Keyboard by touching anywhere using Swift

override func viewDidLoad() { super.viewDidLoad() //Looks for single or multiple taps. let tap = UITapGestureRecognizer(target: self, action: #selector(UIInputViewController.dismissKeyboard)) //Uncomment the line below if you want the tap not not interfere and cancel other interactions. //tap.cancelsTouchesInView = false view.addGestureRecognizer(tap) } //Calls this function when the tap is recognized. @objc func dismissKeyboard() { //Causes the view (or … Read more

Dismiss keyboard by touching background of UITableView

This is easily done by creating a UITapGestureRecognizer object (by default this will detect a “gesture” on a single tap so no further customization is required), specifying a target/action for when the gesture is fired, and then attaching the gesture recognizer object to your table view. E.g. Perhaps in your viewDidLoad method: UITapGestureRecognizer *gestureRecognizer = … Read more

Move view with keyboard using Swift

Here is a solution, without handling the switch from one textField to another: override func viewDidLoad() { super.viewDidLoad() NSNotificationCenter.defaultCenter().addObserver(self, selector: Selector(“keyboardWillShow:”), name: UIKeyboardWillShowNotification, object: nil) NSNotificationCenter.defaultCenter().addObserver(self, selector: Selector(“keyboardWillHide:”), name: UIKeyboardWillHideNotification, object: nil) } func keyboardWillShow(notification: NSNotification) { if let keyboardSize = (notification.userInfo?[UIKeyboardFrameEndUserInfoKey] as? NSValue)?.CGRectValue() { self.view.frame.origin.y -= keyboardSize.height } } func keyboardWillHide(notification: NSNotification) { self.view.frame.origin.y … Read more