1

我使用的是自定義佈局來定位我的UICollectionViewCells像這樣:我如何可以移動(動畫)UICollectionView細胞和出圓形的[PICS]

enter image description here

這個偉大的工程。現在,當我按在左下角的按鈕,我想有所有的細胞興致勃勃地返回到視圖的中心,就像這樣:

enter image description here

我種有這方面的工作,但它根本不是動畫。它只是那種流行的方式。下面是我使用的重載動作的代碼:

- (IBAction)animate:(id)sender { 
[self.collectionView performBatchUpdates:^{ 
    [self.collectionView reloadSections:[NSIndexSet indexSetWithIndex:0]]; 
} completion:nil]; 
} 

而在我的佈局類的,我有我的每個prepareLayout被調用時,調節細胞的layoutAttributesForItemAtIndexPath這樣的中心翻轉的標誌:

- (UICollectionViewLayoutAttributes*) layoutAttributesForItemAtIndexPath:(NSIndexPath *)path { 
UICollectionViewLayoutAttributes *attributes = [UICollectionViewLayoutAttributes layoutAttributesForCellWithIndexPath:path]; 
attributes.size = CGSizeMake(ITEM_SIZEw, ITEM_SIZEh); 

if (self.isCircle) { 
    attributes.center = CGPointMake(_center.x +_radius * 
           cosf(2 * path.item * M_PI/_cellCount), 
           _center.y + _radius * 
           sinf(2 * path.item * M_PI/ _cellCount)); 
} else { 
    attributes.center = [self collectionView].center; 
} 

return attributes; 
} 

如何將單元格的運動動畫化回視圖的中心?

回答

1

嗯,我發現我的答案。做一個不同的佈局,並用動畫切換到它:

[self.collectionView setCollectionViewLayout:home animated:YES]; 
0

儘量把改變一個UIView動畫這樣的:

[UIView animateWithDuration:0.5 animations:^{ 
    if (self.isCircle) { 
     attributes.center = CGPointMake(_center.x +_radius * 
           cosf(2 * path.item * M_PI/_cellCount), 
           _center.y + _radius * 
           sinf(2 * path.item * M_PI/ _cellCount)); 
    } else { 
     attributes.center = [self collectionView].center; 
    } 
}]; 
+0

感謝您的回答,但沒有骰子。仍然沒有動畫。 – Westley