2016-07-21 8 views
3

テーブルビューを表示すると、セルにこのようなアニメーションが表示されます。セルが表示されているかどうかをチェックする方法

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

      cell.alpha = 0 
      let rotation = CATransform3DTranslate(CATransform3DIdentity, -250, 20, 0) 
      cell.layer.transform = rotation 
      UIView.animateWithDuration(0.9){ 
      cell.alpha = 1 
      cell.layer.transform = CATransform3DIdentity 

    } 

それはこのように取り組んだが、私は、アニメーションがまだ存在する前の細胞を見るために再び上昇、その後下がるとするとき。

私はセルが表示されているかどうかを確認する必要があると思う。

私が試したことは、didEndDisplayingCell関数を使用して配列内にcell.tagを配置し、現在のセルがarray.contains(cell.tag)の配列内にあるかどうかを確認していましたが、動作しませんでした。 実際、アニメーションは最初の3つのセルだけで動作し、その後は何も動作しませんでした。

+0

visibleCellsを使用します。目に見える細胞を得る。 –

+0

これを一度ご覧くださいhttp://stackoverflow.com/questions/3326658/determine-if-a-tableview-cell-is-visible –

+0

@ Anbu.Karthikはあなたの答えをありがとうが、私はどの細胞が見えたのかを知りたい表示されているセルにアニメーションが再度使用されることはありません –

答えて

4

インデックスパスの配列を保持し、セルが表示されるたびに追加する必要があります。この方法で、セルがすでにアニメーション化されているかどうかを確認できます。

if (!indexPaths.contains(indexPath)) { 
    indexPaths.append(indexPath) 
    cell.alpha = 0 
    let rotation = CATransform3DTranslate(CATransform3DIdentity, -250, 20, 0) 
    cell.layer.transform = rotation 
    UIView.animateWithDuration(0.9){ 
     cell.alpha = 1 
     cell.layer.transform = CATransform3DIdentity 
    } 
} 
+0

ありがとう..それは働いた! 私はあなたの答えを3分で受け入れます –

1

ジェームズ・Pはコメントで述べた@として - ちょうど配列

var indexPathArray = [NSIndexPath]() 

を作成し、willDisplayCell方法書き換える:あなたが何ができるか

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

    if !indexPathArray.contains(indexPath) { 

     indexPathArray.append(indexPath) 

     cell.alpha = 0 
     let rotation = CATransform3DTranslate(CATransform3DIdentity, -250, 20, 0) 
     cell.layer.transform = rotation 
     UIView.animateWithDuration(0.9){ 
      cell.alpha = 1 
      cell.layer.transform = CATransform3DIdentity 
     } 
    } 
} 
1

は、細胞のindexpathを入れています配列内にindexpathが配列されているかどうかを確認します。インデックスパスが配列内にある場合、アニメーションを実行しません。

関連する問題