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
}
}
从未尝试过这一点,但尝试设置不透明度为0,然后再使用'的tableView( _:willDisplayCell:forRowAtIndexPath:)'将动画设置为1. – Rengers 2015-04-02 09:35:20