3

爲「deleteItemsAtIndexPaths」文件說如何在調用deleteItemsAtIndexPaths之後維護其他UICollectionView單元格的狀態?

"The collection view updates the layout of the remaining items to account for the deletions, animating the remaining items into position as needed." 

在我的情況下,同時刪除從收集的小區查看其所有的細胞都在做一些動畫,但一旦我打電話deleteItemsAtIndexPaths誰動了他們的新位置停止這樣做舊的動畫細胞動畫?

所以我的問題是,由於deleteItemsAtIndexPaths將單元格移動到新位置後,如何保持該狀態不變?

編輯: - 我的所有單元格按比例縮小,做搖晃非常相似「,當用戶長按應用圖標在iPhone刪除應用程序

[UIView animateWithDuration:0.125 
         delay:0 
        options:UIViewAnimationOptionCurveEaseInOut 
       animations:^{ 
    self.transform = CGAffineTransformMakeScale(0.8,0.8); 
} completion:^(BOOL finished){ 

    if(finished) { 
     [self shouldAllowInteraction:NO]; 
     CGAffineTransform leftWobble = CGAffineTransformRotate(self.transform, RADIANS(-1.0)); 
     CGAffineTransform rightWobble = CGAffineTransformRotate(self.transform, RADIANS(1.0)); 
     self.transform = leftWobble; 
     [UIView animateWithDuration:0.125 
           delay:0 options:(UIViewAnimationOptionRepeat | UIViewAnimationOptionAutoreverse | UIViewAnimationOptionAllowUserInteraction) 
         animations:^{ 
      self.transform = rightWobble; 

     } completion:^(BOOL finished) { 

     }]; 
    } 
}]; 

但是,當我試圖刪除使用

細胞。
[cardsViewController.collectionView deleteItemsAtIndexPaths:indexPathArray]; 

所有移動細胞 - (單元格中的刪除單元格後)停止這樣做,擺動和擴大它們不保留相同的行爲意味着動畫

如山姆。 ple gif在這裏。 enter image description here

+0

嗯。我*認爲*我理解這個問題,但是你可以發佈一些示例代碼來證明問題嗎? – 2014-10-12 07:46:04

+0

@ash已更新我的情況與「當用戶嘗試從iPhone中刪除應用程序時非常相似」,所以當用戶刪除應用程序時仍然會發生移動 應用程序圖標不會停止動畫。 – kidsid49 2014-10-12 10:52:31

+0

對於這種事情,你可能不得不超越簡單的基於UIView的動畫,並在圖層本身上使用Core Animation CAAnimation類。收集意見只是不打算以這種方式工作。 – 2014-10-13 08:50:03

回答

4

如果我理解您的要求正確
一)按比例縮小和刪除搖晃
enter image description here
b)和重新排列,不要比例放大/縮小,但繼續搖晃
enter image description here

加這些方法到您的手機

-(void)scaleDownAndWoble 
{ 
    [UIView animateWithDuration:1 
          delay:0 
         options:UIViewAnimationOptionCurveEaseInOut 
        animations:^{ 
         self.transform = CGAffineTransformMakeScale(0.8,0.8); 
        } completion:^(BOOL finished){ 

         if(finished) { 
          [self wobble]; 
         } 
        }]; 


} 

-(void)wobble 
{ 
    CGAffineTransform leftWobble = CGAffineTransformRotate(self.transform, DEGREE(-1.0)); 
    CGAffineTransform rightWobble = CGAffineTransformRotate(self.transform, DEGREE(1.0)); 
    self.transform = leftWobble; 
    [UIView animateWithDuration:0.125 
          delay:0 options:(UIViewAnimationOptionRepeat | UIViewAnimationOptionAutoreverse | UIViewAnimationOptionAllowUserInteraction) 
        animations:^{ 
         self.transform = rightWobble; 

        } completion:^(BOOL finished) { 

        }]; 


} 

現在爲ste第1頁:致電scaleDownAndWoble每個可見單元 第二步:撥打擺動所有可見單元格刪除動畫完成

- (void)deleteItemAtIndexPath:(NSIndexPath *)indexPath 
    { 
     NSMutableArray *colorNames = self.sectionedColorNames[indexPath.section]; 
     [colorNames removeObjectAtIndex:indexPath.item]; 
     [self.collectionView performBatchUpdates:^{ 
      [self.collectionView deleteItemsAtIndexPaths:@[indexPath]]; 

     } 
             completion:^(BOOL finished) { 
              NSArray *array = [self.collectionView visibleCells]; 
              for(ColorNameCell * cell in array) 
              [cell wobble]; 

             }]; 
    } 
+0

我正在做這種東西已經是事情deleteItemsAtIndexPaths做移動單元格上的放大動畫,所以我能夠開始移動細胞再次搖擺gaian再次,但一個放大,然後擺動動畫開始。它像一個小故障 – kidsid49 2014-10-15 12:15:31

+0

@ kidsid49檢查附加的gif,它爲我工作,不重新加載收藏視圖,而是應用擺動動畫可見細胞 – 2014-10-15 12:24:56

+0

你在sizeForItemAtIndexPath傳遞的是什麼縮小的大小?我猜縮小的動畫在你的情況下是自定義流程佈局的事情? – kidsid49 2014-10-15 12:47:52

1

莫非這個答案幫你出來後?

Avoid animation of UICollectionView after reloadItemsAtIndexPaths

看起來像一個方法來禁用某些動畫的UICollection視圖(修改了代碼中的答案,以滿足您的問題):

[UIView animateWithDuration:0 animations:^{ 
    [collectionView performBatchUpdates:^{ 
     [collectionView deleteItemsAtIndexPaths:indexPaths]; 
    } completion:nil]; 
}]; 
+0

我已經嘗試使用iOS 7 Api [UIView performWithoutAnimation:^ {}]; – kidsid49 2014-10-16 11:36:21

相關問題