Ios 动画立即完成,而不考虑持续时间和延迟

Ios 动画立即完成,而不考虑持续时间和延迟,ios,swift,animation,Ios,Swift,Animation,我有这个动画块,但是单元格背景色立即变为清晰: cell.mylabel.backgroundColor = .orange UIView.animate(withDuration: 3.0, delay:3, animations: { cell.mylabel.backgroundColor = .clear }) 关键是我正在cellForRowAt 我尝试将动画移动到自定义单元格,但再次失败: override func didMoveToWindow() {

我有这个动画块,但是
单元格
背景色立即变为
清晰

cell.mylabel.backgroundColor = .orange
UIView.animate(withDuration: 3.0, delay:3, animations: {
    cell.mylabel.backgroundColor = .clear
})
关键是我正在
cellForRowAt

我尝试将动画移动到自定义单元格,但再次失败:

override func didMoveToWindow() {
            UIView.animate(withDuration: 3.0, delay:3, animations: {
                self.mylabel.backgroundColor = .clear
            })
    }
试着这样,

cell.mylabel.layer.backgroundColor = UIColor.redColor().CGColor
UIView.animate(withDuration: 3.0, delay:3, animations: {
    cell.mylabel.layer.backgroundColor = UIColor.clearColor().CGColor
})
关键是我正在
cellForRowAt

这还为时过早,因为单元格可能还不在屏幕视图层次结构中。只能为屏幕视图层次中的视图设置动画。在将单元添加为表视图的子视图后,需要找到一种添加动画的方法

我将创建一个自定义的
UITableViewCell
子类。在子类中,我将重写
didMoveToWindow
,将动画添加到
self


或者,可以覆盖表视图控制器中的
viewdilayoutsubviews
(如果有),并在该方法中添加动画。

为什么要将其更改为层?我找不到视图背景色的动画。是的,当然我们可以使用像-(void)tableView:(UITableView*)tableView willDisplayCell:(UITableViewCell*)cell for RowAtIndexPath:(NSIndexPath*)indexPath{(RouteListCell*)cell.name.backgroundColor=[UIColor clearColor];[(RouteListCell*)cell.name backgroundGlowAnimationFromColor:[UIColor whiteColor]toColor:[UIColor redColor]clearAnimationsFirst:是];}@AVEbrahimi我将来从@Sujit找到这个答案,当你复制其他人的答案时,你应该在你的答案中包含正确的参考。否则这是剽窃。更好的是,如果你认为另一个问题是重复的,请投票以重复的形式关闭该问题。@rmaddy谢谢老兄。我会记住
表中的动画视图:willDisplayCell:ForRowatineXpath:
而不是
表视图:CellForRowatineXpath
使用
表视图:willDisplayCell:ForRowatineXpath:
也可能工作。表视图:willDisplayCell:ForRowatineXpath也不工作,:(