iosswiftuitableviewtableviewuianimation

UIView.animateWithDuration stops after scrolling uitableviewcell


i have added a infinite animation in uiTableViewCell which just blinks a UILabel inside the table view cell.

my problem is, when i scrolls the tableview it just stops the blinking

my code is

func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
    let cell = tableView.dequeueReusableCellWithIdentifier("TripListCell", forIndexPath: indexPath) as! TripListCell
    
    let trip = tripList[indexPath.section]
    cell.lblTripDirection.textColor = UIColor(red: 51/255, green: 210/255, blue: 123/255, alpha: 1.0)
    
    UIView.animateWithDuration(0.5, delay: 0.0, options: [.CurveEaseInOut, .Repeat, .Autoreverse, .AllowUserInteraction], animations: {
        
        cell.lblTripDirection.alpha = 0.0
        }, completion: {
            bool in
        cell.lblTripDirection.alpha = 1.0
        cell.lblTripDirection.textColor = UIColor.blackColor()
    })
    return cell
}

Update:

UIView.commitAnimations() before returning the cell worked for me. Thank you everyone :)


Solution

  • UIView.commitAnimations() before returning the cell worked for me.