我试图编程方式关闭屏幕上的键盘和我有我的代码如下无法为iPhone 5和iPhone5s
override func 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) {
var info = notification.userInfo!
let keyboardFrame: CGRect = (info[UIKeyboardFrameEndUserInfoKey] as! NSValue).CGRectValue()
UIView.animateWithDuration(0.1, animations: {() -> Void in
self.Bottomspace.constant = keyboardFrame.size.height
})
}
func keyboardWillHide(notification: NSNotification){
self.Bottomspace.constant = 0
}
它做工精细的iPhone 6和iPad,而不是iPhone 5和iPhone 5s,有什么建议吗?
就在您点击UITextField外部时? – senty
诺普,我做键盘上的返回键 –