要检测键盘何时出现,您可以听NSNotificationCenter
NSNotificationCenter.defaultCenter().addObserver(self, selector: "keyboardWillShow:", name: UIKeyboardWillShowNotification, object: nil)\nNSNotificationCenter.defaultCenter().addObserver(self, selector: \xe2\x80\x9ckeyboardWillHide:", name: UIKeyboardWillHideNotification, object: nil)\nRun Code Online (Sandbox Code Playgroud)\n\n这将调用keyboardWillShow和keyboardWillHide。在这里你可以用你的UITextfield
func keyboardWillShow(notification: NSNotification) {\n if let userInfo = notification.userInfo {\n if let keyboardSize = (userInfo[UIKeyboardFrameBeginUserInfoKey] as? NSValue)?.CGRectValue() {\n //use keyboardSize.height to determine the height of the keyboard and set the height of your textfield accordingly\n }\n }\n}\n\nfunc keyboardWillHide(notification: NSNotification) {\n //pull everything down again\n}\nRun Code Online (Sandbox Code Playgroud)\n
| 归档时间: |
|
| 查看次数: |
1134 次 |
| 最近记录: |