2017-05-17 10 views
1

iOSチャットアプリケーションを開発していて、チャットビューに問題があります。私はチャットビューのためにUITableViewControllerを使用しています。時々私のテーブルはビデオで見ることができるように新しい行が挿入されたときにジャンプします:https://youtu.be/8IgEUJ5uYAciOS UITableViewController - 下に挿入して下にスクロールする - 時にはジャンプする

 self.conversation.append(message) 

     self.tableView.beginUpdates() 
     self.tableView.insertRows(at: [IndexPath(row: self.conversation.count - 1, section: 0)], with: UITableViewRowAnimation.none) 
     self.tableView.endUpdates() 


     DispatchQueue.main.async { 
      self.tableView.scrollToRow(at: IndexPath(row: self.conversation.count - 1, section: 0), at: UITableViewScrollPosition.bottom, animated: false) 
      self.footerView?.isHidden = true 
      self.theMessage.text = nil 
      self.switchBottomActions(showSend: false) 
     } 

各メッセージオブジェクトは、estimatedMessageHeightというプロパティを持っています

これは私が挿入し、表の一番下までスクロールしてる方法です。そこにメッセージのセルサイズを保存していますので、tableViewのheightForRowAtコードは

です。

+0

ストーリーボードのバウンスオプションをオフにします。 –

+0

@Robert Constantinescu、解決方法を見つけましたか?正解を投稿してください。 WhatsAppのようなボトムローを挿入してアニメーションしたい –

答えて

0

UITableViewのアトリビュートインスペクタでをバウンスにしてをオフにする必要があります。 enter image description here

+0

いいえ、それは私を助けなかった。 –

2

私も同じ問題に直面していましたが、ついに私は次の解決策に陥りました。それは私にWhatsAppアプリケーションのような同じアニメーション感を与える。

UIView.animate(withDuration: 1, delay: 0, usingSpringWithDamping: 0.8, initialSpringVelocity: 0, options: [], animations: { 

     let reloadIndexPath = IndexPath(item: self.arrTableVwData.count - 1, section: 0) 

     self.tableVw.beginUpdates() 
     self.tableVw.insertRows(at:[reloadIndexPath], with: UITableViewRowAnimation.fade) 
     self.tableVw.endUpdates() 
     self.tableVw.scrollToRow(at: reloadIndexPath, at: .bottom, animated: false) 

    }, completion: nil) 

注:我々はすでにinsertRowsscrollToRow方法でそれらを渡すようoptions:[]内の任意のアニメーションの種類を通過しないでください。

0

この機能行います

func scrollToBottom(){ 
    DispatchQueue.main.async { 
     let indexPath = IndexPath(row: self.chatListDB.count-1, section: 0) 
     self.tblView.scrollToRow(at: indexPath, at: .bottom, animated: false) 
    } 
} 

をして値を挿入した後、それを呼び出します。

関連する問題