我創建了一個聊天視圖,其中使用了 tableview,ChatView 的基本功能是顯示最新訊息(最后一個單元格),但是 tableView 沒有滾動到最后一個索引,它總是卡在中間的某個地方
func scrollToBottom() {
let point = CGPoint(x: 0, y: self.chatTableView.contentSize.height 200.0)
self.chatTableView.setContentOffset(point, animated: true)
}
uj5u.com熱心網友回復:
斯威夫特 5
嗨,你只需要在加載表視圖后呼叫這行代碼。
self. chatTableView.scrollToRow(at: IndexPath(row: lastRowIndex, section: 0), at: .bottom, animated: true)
uj5u.com熱心網友回復:
override func viewDidLoad() {
super.viewDidLoad()
DispatchQueue.main.asyncAfter(deadline: .now() 0.25) {
self.scrollToBottom()
}
}
private func scrollToBottom(){
let y = self.collectionView.contentSize.height - self.collectionView.btHeight() self.collectionView.adjustedContentInset.bottom
self.collectionView.setContentOffset(CGPoint.init(x: 0, y: y), animated: false)
if self.loadingView.superview != nil {
self.loadingView.removeFromSuperview()
}
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/326569.html
