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