Explorar o código

relayout message cells on screen orientation change

cyberta %!s(int64=5) %!d(string=hai) anos
pai
achega
e0f7bed4a9
Modificáronse 1 ficheiros con 14 adicións e 0 borrados
  1. 14 0
      deltachat-ios/Controller/ChatViewController.swift

+ 14 - 0
deltachat-ios/Controller/ChatViewController.swift

@@ -115,6 +115,13 @@ class ChatViewController: MessagesViewController {
                                        selector: #selector(setTextDraft),
                                        name: UIApplication.willResignActiveNotification,
                                        object: nil)
+        notificationCenter.addObserver(self, selector: #selector(rotated),
+                                       name: UIDevice.orientationDidChangeNotification,
+                                       object: nil)
+    }
+
+    deinit {
+        NotificationCenter.default.removeObserver(self, name: UIDevice.orientationDidChangeNotification, object: nil)
     }
 
     private func startTimer() {
@@ -382,6 +389,13 @@ class ChatViewController: MessagesViewController {
         }
     }
 
+    @objc private func rotated() {
+        self.messagesCollectionView.reloadDataAndKeepOffset()
+        if self.isLastSectionVisible() {
+            self.messagesCollectionView.scrollToBottom(animated: true)
+        }
+    }
+
     private func configureMessageMenu() {
         var menuItems: [UIMenuItem]