我試圖編程方式關閉屏幕上的鍵盤和我有我的代碼如下無法爲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
諾普,我做鍵盤上的返回鍵 –