我在 UICollectionViewCell 中有一个 ImageView,比如 imageViewA,比如 ComicStripViewCellA.xib。如果条件为真,我需要重新定位 imageViewA。我可以访问 imageViewA 或在 collectionView:cellForItemAtIndexPath 中更改其 alpha 值,但如果这是此 viewCell 第一次出队,则无法重新定位它。
但是如果这个 viewCell 已经在池中,我可以在下次执行 collectionView:cellForItemAtIndexPath 时重新定位它。
-(UICollectionView *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath 
{
     id <ComicStripViewCell> viewCell = [collectionView dequeueReusableCellWithReuseIdentifier:@"comicStripCell" forIndexPath:indexPath];
     if (condition) {
          viewCell.imageViewA.alpha = 0.5;  // Always work.
          [viewCell reposition:YES];  // Only work if viewCell is already in the pool.
     }
     return (UICollectionView *)viewCell;
}
以下例程在 ComicStripViewCellA.m 中:
-(void)reposition:(BOOL)flag
{
     if (flag) {
          CGPoint center = _imageViewA.center;
          center.x -= 60;
          _imageViewA.center = center;
     }
}
我想这与运行重新定位例程时未完成的视图单元初始化有关,但我不确定。
任何帮助表示赞赏!
谢谢!