0
私はチャットアプリで作業しており、ユーザーにキーボードを対話的に却下させようとしていました。私はそれを予想通り残念ながら、それは働いていません。キーボードを閉じるためのスムーズな切り替え
(これはダウンキーボードを引っ張って始めて私と一緒にいる私はどんなキーボードの上に滞在しないように私のテキストビューをしたいと思います。ここで私が試したものです:viewDidLoad
で
:
同じクラスでtextView.keyboardDismissMode = .interactive//I have tried the same thing with the table view as well, but it produces the same result.
NotificationCenter.default.addObserver(self, selector: #selector(self.keyboardWillHide(_:)), name: NSNotification.Name.UIKeyboardWillHide, object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(self.keyboardWillShow(_:)), name: NSNotification.Name.UIKeyboardWillShow, object: nil)
:
func keyboardWillShow(_ aNotification: NSNotification) {
let info = aNotification.userInfo!
let keyboardFrame = (info[UIKeyboardFrameEndUserInfoKey] as! NSValue).cgRectValue()
UIView.animate(withDuration: 0.25) {() -> Void in
self.messageBottomConstraint.constant = keyboardFrame.height
self.view.layoutIfNeeded()
}
}
func keyboardWillHide(_ aNotification: NSNotification) {
UIView.animate(withDuration: 0.25) {() -> Void in
self.messageBottomConstraint.constant = 0
self.view.layoutIfNeeded()
}
}
ユーザーがキーボードを消している間にキーボードの上部にテキストビューを保存するにはどうすればよいですか?ありがとう!
例を教えてください。ブログの投稿はObj-Cで、私はそれを変換するのに少し苦労しています...ありがとう! – penatheboss