Created
May 6, 2016 02:42
-
-
Save yamazaki-sensei/5170e0142d89e9904cabea78ec032a05 to your computer and use it in GitHub Desktop.
UIKeyboardDidShowNotificationが上がってきているのにキーボードが開かないことがある話 ref: http://qiita.com/almichest/items/ebb313822086e5e5ad2c
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| willShow1 | |
| didShow | |
| willShow2 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import UIKit | |
| class ViewController: UIViewController { | |
| override func viewDidLoad() { | |
| super.viewDidLoad() | |
| let textField = UITextField(frame: CGRect(x: 100, y: 100, width: 50, height: 30)) | |
| textField.backgroundColor = UIColor.redColor() | |
| view.addSubview(textField) | |
| NSNotificationCenter.defaultCenter().addObserver(self, selector: #selector(ViewController.keyboardWillShow(_:)), name: UIKeyboardWillShowNotification, object: nil) | |
| NSNotificationCenter.defaultCenter().addObserver(self, selector: #selector(ViewController.keyboardDidShow(_:)), name: UIKeyboardDidShowNotification, object: nil) | |
| } | |
| } | |
| extension ViewController { | |
| func keyboardWillShow(notification: NSNotification) { | |
| print("willShow1") | |
| view.endEditing(true) | |
| print("willShow2") | |
| } | |
| func keyboardDidShow(notification: NSNotification) { | |
| print("didShow") | |
| } | |
| } | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment