2016-05-19 20 views
3

Ich habe eine unendliche Animation in uiTableViewCell hinzugefügt, die nur ein UILabel in der Tabellenansicht Zelle blinkt.UIView.animateWithDuration stoppt nach dem Scrollen uitableviewcell

mein Problem ist, wenn ich die Tableview rollt sie hält nur das Blinken

meinen Code

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 ist:

UIView.commitAnimations() für mich gearbeitet. Vielen Dank an alle :)

Antwort

0

UIView.comitmitAnimations() arbeitete für mich.

+0

Wo haben Sie die UIView.comititAnimations() deklariert? Hast du ein funktionierendes Beispiel? –

1

Sie können jedes Mal in Ihrer benutzerdefinierten Zelle prepareForReuse Methode des UITableViewCell außer Kraft setzen, wenn dequeueReusableCellWithIdentifier heißt TripListCell

prepareForReuse aufgerufen.

hoffe das hilft!

0

Sie sollten Ihren Code in diesem UITableViewDelegate Methode setzen:

func tableView(tableView: UITableView, willDisplayCell cell: UITableViewCell, forRowAtIndexPath indexPath: NSIndexPath); 
1

Es ist, weil cellForRowAtIndexPath resuse derselben Zelle andere Daten anzuzeigen. also schreibst du deine Animation nicht in cellForRowAtIndexPath.

Sie sollten versuchen, in awakeFromNib von custom cell class schreiben, oder Sie sollten willDisplayCell Methode verwenden, um Animation zu schreiben.

hoffen, dass dies helfen :)

+0

watchFromNib: Problem bleibt gleich, –

+0

willDisplayCell: funktioniert nicht –

+0

@ParthBhuva das ist eine sehr alte Frage, aber haben Sie am Ende diese Lösung? –

0

Tableviews wieder verwenden ihre Zellen so zwangsläufig Ihr Label ihre Animation zu stoppen.

Sie können die wiederverwendete Zelle in den Standardzustand entweder in prepareForReuse: in der benutzerdefinierten Tabellenansichtszelle oder in tableView:willDisplayCell:forRowAtIndexPath: delegate method wiederherstellen.

In diesem Fall verwenden Sie UIView-Animationen. Sie müssen nur den Wert der animierten Eigenschaft ändern, um die Animation abzubrechen und zum Standardzustand zurückzukehren.

func tableView(tableView: UITableView, willDisplayCell cell: UITableViewCell, forRowAtIndexPath indexPath: NSIndexPath) { 

    //declaring the cell variable again 

    var cell: TripListCell = self.tableView.dequeueReusableCellWithIdentifier("cell") as! TripListCell 
    UIView.performWithoutAnimation { 
     cell.lblTripDirection.layoutIfNeeded() 
    } 
    // do your animation.. 
    ... 
}