Bläddra i källkod

rely on content inset auto adjustment of UITableViewController. Scroll only down if keyboard appears

cyberta 4 år sedan
förälder
incheckning
e50c510153
1 ändrade filer med 9 tillägg och 7 borttagningar
  1. 9 7
      deltachat-ios/Chat/ChatViewControllerNew.swift

+ 9 - 7
deltachat-ios/Chat/ChatViewControllerNew.swift

@@ -153,19 +153,21 @@ class ChatViewControllerNew: UITableViewController {
     }
     }
 
 
     @objc func keyboardWillShow(_ notification: Notification) {
     @objc func keyboardWillShow(_ notification: Notification) {
-        if let keyboardSize = (notification.userInfo?[UIResponder.keyboardFrameEndUserInfoKey] as? NSValue)?.cgRectValue,
-           tableView.inputAccessoryView?.frame.height ?? 0 < keyboardSize.height {
-            let wasLastRowVisible = self.isLastRowVisible()
-            self.tableView.contentInset.bottom = keyboardSize.height - (tableView.inputAccessoryView?.frame.height ?? 0)
-            if wasLastRowVisible {
-                self.scrollToBottom(animated: false)
+        if let keyboardSize = (notification.userInfo?[UIResponder.keyboardFrameEndUserInfoKey] as? NSValue)?.cgRectValue {
+            if keyboardSize.height > tableView.inputAccessoryView?.frame.height ?? 0 {
+                if self.isLastRowVisible() {
+                    DispatchQueue.global(qos: .userInteractive).asyncAfter(deadline: .now() + 0.01) {
+                        DispatchQueue.main.async { [weak self] in
+                            self?.scrollToBottom(animated: true)
+                        }
+                    }
+                }
             }
             }
         }
         }
     }
     }
 
 
     @objc func keyboardWillHide(_ notification: Notification) {
     @objc func keyboardWillHide(_ notification: Notification) {
         isKeyboardShown = false
         isKeyboardShown = false
-        self.tableView.contentInset.bottom = 0
     }
     }
 
 
     private func startTimer() {
     private func startTimer() {