Skip to content

Instantly share code, notes, and snippets.

@yamazaki-sensei
Created May 6, 2016 02:42
Show Gist options
  • Select an option

  • Save yamazaki-sensei/5170e0142d89e9904cabea78ec032a05 to your computer and use it in GitHub Desktop.

Select an option

Save yamazaki-sensei/5170e0142d89e9904cabea78ec032a05 to your computer and use it in GitHub Desktop.
UIKeyboardDidShowNotificationが上がってきているのにキーボードが開かないことがある話 ref: http://qiita.com/almichest/items/ebb313822086e5e5ad2c
willShow1
didShow
willShow2
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