Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //// Vladimir Zhelnov - neatek.pw - Web/iOS dev
- var keyboard_s = false
- override func viewDidLoad() {
- NotificationCenter.default.addObserver(self, selector: #selector(ViewController.keyboardWillShow), name: NSNotification.Name.UIKeyboardWillShow, object: nil)
- NotificationCenter.default.addObserver(self, selector: #selector(ViewController.keyboardWillHide), name: NSNotification.Name.UIKeyboardWillHide, object: nil)
- HERE_IS_TEXTFIELD.addTarget(self, action: #selector(ViewController.myTargetFunction), for: UIControlEvents.touchDown)
- }
- func myTargetFunction(textField: UITextField) {
- if(keyboard_s) {
- view.endEditing(true)
- }
- }
- func keyboardWillShow(notification:NSNotification) {
- print("Show")
- keyboard_s = true
- }
- func keyboardWillHide(notification:NSNotification) {
- print("Hide")
- keyboard_s = false
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement