当键盘快速显示时移动文本字段
我正在使用Swift进行iOS编程,我正在使用此代码移动UITextField,但它不起作用。我keyboardWillShow正确调用该函数,但文本字段不移动。我正在使用autolayout。
override func viewDidLoad() {
super.viewDidLoad()
NSNotificationCenter.defaultCenter().addObserver(self, selector: Selector("keyboardWillShow:"), name:UIKeyboardWillShowNotification, object: nil);
NSNotificationCenter.defaultCenter().addObserver(self, selector: Selector("keyboardWillHide:"), name:UIKeyboardWillHideNotification, object: nil);}deinit {
NSNotificationCenter.defaultCenter().removeObserver(self);}func keyboardWillShow(notification: NSNotification) {
if let keyboardSize = (notification.userInfo?[UIKeyboardFrameBeginUserInfoKey] as? NSValue)?.CGRectValue() {
//let contentInsets = UIEdgeInsets(top: 0, left: 0, bottom: keyboardSize.height, right: 0)
var frame = self.ChatField.frame
frame.origin.y = frame.origin.y - keyboardSize.height + 167
self.chatField.frame = frame
println("asdasd")
}}
慕慕森
守着一只汪
随时随地看视频慕课网APP