Browse Source

adapt tableView on keyboard appering/disappearing by changing contentInset instead of frame

cyberta 4 years ago
parent
commit
fc70ba54c3
1 changed files with 4 additions and 14 deletions
  1. 4 14
      deltachat-ios/Chat/ChatViewControllerNew.swift

+ 4 - 14
deltachat-ios/Chat/ChatViewControllerNew.swift

@@ -17,7 +17,6 @@ class ChatViewControllerNew: UITableViewController {
     var incomingMsgObserver: Any?
     var ephemeralTimerModifiedObserver: Any?
 
-    var originFrame: CGRect?
     var lastContentOffset: CGFloat = -1
     var isKeyboardShown: Bool = false
 
@@ -156,26 +155,17 @@ class ChatViewControllerNew: UITableViewController {
     @objc func keyboardWillShow(_ notification: Notification) {
         if let keyboardSize = (notification.userInfo?[UIResponder.keyboardFrameEndUserInfoKey] as? NSValue)?.cgRectValue,
            tableView.inputAccessoryView?.frame.height ?? 0 < keyboardSize.height {
-            originFrame = self.tableView.frame
             let wasLastRowVisible = self.isLastRowVisible()
-            if let originFrame = originFrame {
-                self.tableView.frame = CGRect(origin: originFrame.origin,
-                                              size: CGSize(width: originFrame.width, height: originFrame.height - keyboardSize.height))
-
-                if wasLastRowVisible {
-                    self.scrollToBottom(animated: false)
-                }
+            self.tableView.contentInset.bottom = keyboardSize.height - (tableView.inputAccessoryView?.frame.height ?? 0)
+            if wasLastRowVisible {
+                self.scrollToBottom(animated: false)
             }
         }
     }
 
     @objc func keyboardWillHide(_ notification: Notification) {
-        if let keyboardSize = (notification.userInfo?[UIResponder.keyboardFrameEndUserInfoKey] as? NSValue)?.cgRectValue,
-           keyboardSize.height == 0,
-           let originFrame = originFrame {
-            self.tableView.frame = originFrame
-        }
         isKeyboardShown = false
+        self.tableView.contentInset.bottom = 0
     }
 
     private func startTimer() {