2016-05-19 5 views
3

テーブルビューのセル内でUILabelを点滅させるuiTableViewCellに無限のアニメーションを追加しました。私のために働いたUIView.animateWithDurationはuitableviewcellをスクロールした後に終了します

UIView.commitAnimations():

私の問題は、私はそれだけで点滅

私のコードは

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 
} 

アップデートで停止したテーブルビューをスクロールしたときに、です。 は、カスタムセルTripListCell

prepareForReuseでのUITableViewCellのprepareForReuseメソッドをオーバーライドすることができ、あなたにみんな:)

答えて

0

UIView.commitAnimationsは()私のために働きました。

+0

どこでUIView.commitAnimations()を宣言しましたか?実際の例がありますか? –

1

ありがとうdequeueReusableCellWithIdentifierが呼ばれるたびに毎回呼ばれます。

願っています!

0

あなたはこのUITableViewDelegate方法でコードを置く必要があります。

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

cellForRowAtIndexPathは、他のデータを表示するには、同じセルは再使用するのでそれはあります。あなたはアニメーションをcellForRowAtIndexPathに書いてはいけません。

awakeFromNibcustom cell classに書き込むか、willDisplayCellメソッドを使用してアニメーションを書き込む必要があります。これは:)

+0

awakeFromNib:問題は同じままです。 –

+0

willDisplayCell:動作しません。 –

+0

@ParthBhuvaこれは非常に古い質問ですが、これを解決しましたか? –

0

TableViewsはとても必然的にあなたのラベルが自分のアニメーションを停止し、その細胞を再利用するのに役立ちます

は希望。

再表示されたセルは、カスタムテーブルビューセルのprepareForReuse:またはのいずれかの既定の状態に復元できます。

この場合、UIViewアニメーションを使用します。アニメーションをキャンセルしてデフォルトの状態に戻るには、アニメーションプロパティの値を変更するだけです。

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.. 
    ... 
} 
関連する問題