我在Xcode 6上快速使用UITableView遇到麻烦:
我希望UITableView单元格在出现/消失时淡入/淡出。
我在网上看了很多淡入淡出的动画,但是找不到想要的东西,因为它基于持续时间动画。
我认为我需要的是一种基于alpha的蒙版?我不是苏尔,我什至都不知道必须创建一个...
我有一个UIViewController,其中包含tableView和UITableView的上下左右的空白(目前)。
谢谢你的帮助 !!
最好,
Anatole
animateWithDuration似乎是适当的,因为淡入/淡出具有持续时间:该单元随着时间逐渐变得可见或不可见。
这是使表格单元淡入的示例:
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
var cell = self.tableView.dequeueReusableCellWithIdentifier("cell") as UITableViewCell
cell.textLabel?.text = self.items[indexPath.row]
cell.backgroundColor = UIColor.grayColor()
cell.alpha = 0
UIView.animateWithDuration(2, animations: { cell.alpha = 1 })
return cell
}
编辑:
这将根据其y位置设置单元格的alpha,这可能更接近您想要的位置:
func scrollViewDidScroll(scrollView: UIScrollView) {
for cell in tableView.visibleCells() as [UITableViewCell] {
var point = tableView.convertPoint(cell.center, toView: tableView.superview)
cell.alpha = ((point.y * 100) / tableView.bounds.maxY) / 100
}
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句