1
我正在研究具有註釋和用戶的應用程序,我需要用戶將註釋插入到表格視圖中,我面臨的問題是關於鍵盤的位置,當用戶按下文本時字段來編寫鍵盤出現的註釋和文本字段,如下面的代碼所示。TextFiled鍵盤問題
但問題是,當我更改鍵盤的語言,將鍵盤更改爲表情符號或打開autocorrection覆蓋的文本字段,將不會隨鍵盤佈局移動。
override func viewWillAppear(animated: Bool) {
super.viewWillAppear(animated)
// KeyBoard Show and Hide
NSNotificationCenter.defaultCenter().addObserver(self, selector: #selector(Commants_Page.keyboardWillShow(_:)), name: UIKeyboardWillShowNotification, object:nil)
NSNotificationCenter.defaultCenter().addObserver(self, selector: #selector(Commants_Page.keyboardWillHide(_:)), name: UIKeyboardWillHideNotification, object: nil)
NSNotificationCenter.defaultCenter().addObserver(self,selector: #selector(Commants_Page.adjustForKeyboard(_:)),name: UIKeyboardWillChangeFrameNotification,object: nil)
}
// KeyBoard Show and Hide Function
func keyboardWillShow(notification: NSNotification) {
if KeyBoardMove == false {
if let keyboardSize = (notification.userInfo?[UIKeyboardFrameBeginUserInfoKey] as? NSValue)?.CGRectValue() {
self.view.frame.origin.y -= keyboardSize.height
KeyBoardMove = true
}
}
}
func keyboardWillHide(notification: NSNotification) {
if KeyBoardMove == true {
if let keyboardSize = (notification.userInfo?[UIKeyboardFrameEndUserInfoKey] as? NSValue)?.CGRectValue() {
self.view.frame.origin.y += keyboardSize.height
KeyBoardMove = false
}
}
}
感謝其幫助我,但輸精管的方式,但仍然它不是完美的方式,因爲當用戶打開該預測選項提交的文本消失 –
然後有很多可用的庫,它可以處理它。你可以看看https://github.com/michaeltyson/TPKeyboardAvoiding – iRiziya
謝謝iRiziya我會檢查它 –