底部的灰色框是文本视图.当我点击文本视图时,键盘将从底部弹出.但是,弹出键盘已覆盖文本视图. 当键盘弹出时,我应该添加什么功能才能向上移动整个视图? 要检测键盘何时显示,您可
当键盘弹出时,我应该添加什么功能才能向上移动整个视图?
要检测键盘何时显示,您可以收听NSNotificationCenterNSNotificationCenter.defaultCenter().addObserver(self, selector: "keyboardWillShow:", name: UIKeyboardWillShowNotification, object: nil) NSNotificationCenter.defaultCenter().addObserver(self, selector: “keyboardWillHide:", name: UIKeyboardWillHideNotification, object: nil)
那会调用keyboardWillShow和keyboardWillHide.在这里,您可以使用UITextfield完成所需的操作
func keyboardWillShow(notification: NSNotification) { if let userInfo = notification.userInfo { if let keyboardSize = (userInfo[UIKeyboardFrameBeginUserInfoKey] as? NSValue)?.CGRectValue() { //use keyboardSize.height to determine the height of the keyboard and set the height of your textfield accordingly } } } func keyboardWillHide(notification: NSNotification) { //pull everything down again }