我尝试使用此代码淡出tableView中的第一个单元格但该代码仅在滚动表格时起作用我需要像Instagram实时流媒体聊天一样工作
streamController.swift
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -
> UITableViewCell {
var cell = tableView.dequeueReusableCell(withIdentifier: "chatcell", for:
indexPath) as! ChatTableCell
cellForRowAtChatTable(&cell, indexPath)
cell.alpha = 0.25
UIView.animate(withDuration: 0.5, animations: {cell.alpha = 1
})
return cell
}
func scrollViewDidScroll(_ scrollView: UIScrollView) {
let cellCount = chatTableView.visibleCells.count
let alphaInterval:CGFloat = 1.0 / CGFloat(cellCount / 2)
for (index,cell) in (chatTableView.visibleCells as
[UITableViewCell]).enumerated() {
if index > cellCount / 2 {
// cell.alpha = CGFloat(index) * alphaInterval
cell.alpha = CGFloat(cellCount - index) * (alphaInterval)
}
}
}