gpt4 book ai didi

uitableview - Swift - UITableView 中的褪色单元格

转载 作者:搜寻专家 更新时间:2023-10-30 22:05:11 24 4
gpt4 key购买 nike

我在 Xcode 6 上快速使用 UITableView 时遇到问题:

我希望我的 UITableView 单元格在出现/消失时淡入/淡出。

我在网上找了很多淡入淡出动画,但没有找到我想要的,因为它是基于持续时间动画的。

我想我需要的是一种基于 alpha 的掩码?我不是 sur,我什至不知道必须创建一个...

我有一个 UIViewController,其中包含一个 tableView 和 UITableView 的一些空白(目前)。

谢谢你的帮助!!

最好的,

阿纳托利

最佳答案

我一直在寻找同样的东西,最后我自己做了,我想我会分享它:

func scrollViewDidScroll(_ scrollView: UIScrollView) {

let cellCount = tableView.visibleCells.count
let alphaInterval:CGFloat = 1.0 / CGFloat(cellCount / 2)

for (index,cell) in (tableView.visibleCells as [UITableViewCell]).enumerated() {

if index < cellCount / 2 {
cell.alpha = CGFloat(index) * alphaInterval
} else {
cell.alpha = CGFloat(cellCount - index) * (alphaInterval)
}
}
}

这是单元格:

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = UITableViewCell()
cell.textLabel?.text = countries[indexPath.row].uppercased()
cell.textLabel?.textColor = .white
cell.backgroundColor = .clear
cell.alpha = 0.25

UIView.animate(withDuration: 0.5, animations: {
cell.alpha = 1
})

return cell
}

最终看起来像这样:

tableViewCell fade

关于uitableview - Swift - UITableView 中的褪色单元格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29409405/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com