ソースを参照

move view frame up if keyboard appears

cyberta 4 年 前
コミット
bba4c72c14
1 ファイル変更18 行追加0 行削除
  1. 18 0
      deltachat-ios/Chat/ChatViewControllerNew.swift

+ 18 - 0
deltachat-ios/Chat/ChatViewControllerNew.swift

@@ -139,6 +139,24 @@ class ChatViewControllerNew: UITableViewController {
                                        selector: #selector(setTextDraft),
                                        name: UIApplication.willResignActiveNotification,
                                        object: nil)
+        notificationCenter.addObserver(self, selector: #selector(keyboardWillShow(_:)), name: UIResponder.keyboardWillShowNotification, object: nil)
+        notificationCenter.addObserver(self, selector: #selector(keyboardWillHide(_:)), name: UIResponder.keyboardWillHideNotification, object: nil)
+    }
+
+    @objc func keyboardWillShow(_ notification: Notification) {
+        if let keyboardSize = (notification.userInfo?[UIResponder.keyboardFrameEndUserInfoKey] as? NSValue)?.cgRectValue {
+            if self.view.frame.origin.y == 0 && tableView.inputAccessoryView?.frame.height ?? 0 < keyboardSize.height {
+                self.view.frame.origin.y -= keyboardSize.height
+            }
+        }
+    }
+
+    @objc func keyboardWillHide(_ notification: Notification) {
+        if let keyboardSize = (notification.userInfo?[UIResponder.keyboardFrameEndUserInfoKey] as? NSValue)?.cgRectValue {
+            if self.view.frame.origin.y != 0 {
+                self.view.frame.origin.y += keyboardSize.height
+            }
+        }
     }
 
     private func startTimer() {