キーボードでシフトアップではない、ここに私の問題ですスタックビュー私はいくつかの異なるものを含むUIView
を持っています。ボトムビューでは、私はUITextView
を持っています。私が理想的には、入力を開始するときに上に移動したいので、実際に私が入力しているものを見ることができます。はUITextView私はSOこれを理解しようとする日の大半を費やしてきた
実装ソリューションはhere、here、here、hereを発見した、と私は代わりにUITextView
の最後のビューでUITextField
を持っている場合は、このトピックに関する他のすべての同様の前の質問には動作しますが、私は本当に、リターンキーを持っていると思います/マルチライン機能は、UITextView
を必要とするようです。ここで
は、私は(いくつかの上記のリンクあたり)コードの面で持っているものです。
func registerForKeyboardNotifications() {
NotificationCenter.default.addObserver(self, selector: #selector(keyboardWasShown(_:)), name: .UIKeyboardDidShow, object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(keyboardWillBeHidden(_:)), name: .UIKeyboardWillHide, object: nil)
}
func keyboardWasShown(_ notification: NSNotification) {
guard let info = notification.userInfo, let keyboardFrameValue = info[UIKeyboardFrameBeginUserInfoKey] as? NSValue else { return }
let keyboardFrame = keyboardFrameValue.cgRectValue
let keyboardSize = keyboardFrame.size
let contentInsets = UIEdgeInsetsMake(0.0, 0.0, keyboardSize.height, 0.0)
scrollView.contentInset = contentInsets
scrollView.scrollIndicatorInsets = contentInsets
}
func keyboardWillBeHidden(_ notification: NSNotification) {
let contentInsets = UIEdgeInsets.zero
scrollView.contentInset = contentInsets
scrollView.scrollIndicatorInsets = contentInsets
}
私はviewDidLoad()
でregisterForKeyboardNotifications()
と呼ばれてきたが、これは私がUITextField
を使用する場合完璧を作業していて、ためていますどんな理由であれ、機能はUITextView
で動作しません。問題に最も近いSOの質問はthis oneですが、問題はUITextView
を含む実行可能な解決策で決して答えられませんでした。私はいくつかの投稿IQKeyboardManagerを参照して見てきましたが、私は理想的にこれをネイティブに修正したいと思います。