AVEbrahimi AVEbrahimi - 2 months ago 7
Swift Question

Animation finishes immediately, regardless of duration and delay

I have this animation block, but the

cell
background color is
clear
immediately:

cell.mylabel.backgroundColor = .orange
UIView.animate(withDuration: 3.0, delay:3, animations: {
cell.mylabel.backgroundColor = .clear
})


The point is I am running this in
cellForRowAt


I tried moving animation to my custom cell, but no success again:

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

Answer

Try like this,

cell.mylabel.layer.backgroundColor = UIColor.redColor().CGColor
UIView.animate(withDuration: 3.0, delay:3, animations: {
    cell.mylabel.layer.backgroundColor = UIColor.clearColor().CGColor
})