2017-01-20 9 views
1

カスタムコレクションビューのセル(アイテム)があります。私は各項目に多くのUILabelsがあります。サーバーのデータによっては、ラベルを適切に更新したいと考えています。対応する項目をリロードしてデータを更新すると正常に動作します。コード:cellForItemAtIndexPath方法でUICollectionViewCellでUILabelのUIViewアニメーションブロックが機能しない

isUpdate = YES; 
[_collectionView performBatchUpdates:^{ 
        [_collectionView reloadItemsAtIndexPaths:bufferUpdateRow]; 
       } completion:^(BOOL finished) {}]; 

、私は変更をチェックし、いずれかが存在する場合、私は、アニメーションブロックを使用したいが、それは動作していないようです。

-(UICollectionViewCell*)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath { 

    static NSString *cellID = @"CellID"; 

    CollectionViewCell *cell = (CollectionViewCell*)[collectionView dequeueReusableCellWithReuseIdentifier:cellID forIndexPath:indexPath]; 

// Update label content here 

    if (isUpdate) { 
     _label1.layer.backgroundColor = [UIColor redColor]; 
     [UIView animateWithDuration:1 delay:0 options:UIViewAnimationOptionAllowUserInteraction animations:^(void) { 
       _label1.layer.backgroundColor=[UIColor clearColor].CGColor; 
     } completion:nil]; 

     isUpdate = NO; 
    } 
    return cell; 
} 

ラベルが赤く点滅しません。代わりに、それは明らかに残っています。アニメーションブロックを削除すると、ラベルが赤くなります(更新検出が正常に動作していることがわかります)。 Plsヘルプ

答えて

1

は赤色の背景が再び明確にそれを設定する前に表示されていることを確認します。これを実現する1つの方法は、別のアニメーションの完成ブロックにアニメーションを配置することです。

[UIView animateWithDuration:0.0 delay:0 options:UIViewAnimationOptionAllowUserInteraction animations:^(void) { 
    self.view.layer.backgroundColor = [UIColor redColor].CGColor; 
} completion:^(BOOL finished) { 
    [UIView animateWithDuration:1 delay:0 options:UIViewAnimationOptionAllowUserInteraction animations:^(void) { 
     self.view.layer.backgroundColor=[UIColor clearColor].CGColor; 
    } completion:nil]; 
}]; 
+0

これは機能します。ありがとうございました! – GeneCode

1

これは、cellForRowAtIndexPathメソッドでアニメーションを作成しているためです。このメソッドは、セルを初期化し、アニメーション化するのではなく、データを設定するためのものです。

あなたはUITableViewDelegateを実装し、より良いチャンスを持っており、内部のコードを配置したい:

func tableView(tableView: UITableView, willDisplayCell: UITableViewCell, forRowAtIndexPath: NSIndexPath) 
関連する問題