2013-05-30 63 views
1

有一種方法可以自定義通過performBatchUpdates完成的動畫定時嗎?UICollectionViewCell performBatchUpdates動畫時間

我有這樣的代碼

[self.stepCollectionView performBatchUpdates:^{ 
    self.stepSelectedIndex = indexPath.row; 

    UICollectionViewCell *cell = [self.stepCollectionView cellForItemAtIndexPath:indexPath]; 

    [UIView transitionWithView:cell 
         duration:0.5f 
         options: UIViewAnimationOptionLayoutSubviews | UIViewAnimationOptionBeginFromCurrentState 
        animations:^{ 
         CGRect frame = cell.frame; 
         frame.size.height = 416; 
         cell.frame = frame; 
        } 
        completion:^(BOOL finished) { 
        }]; 
    } completion:^(BOOL finished) {   
}]; 

我會改變UICollectionViewCell的高度,並在同一時間重組UICollectionViewCell的子視圖。

+0

見http://stackoverflow.com/questions/12922780/how-do-you-set-the-找到示例的完整源代碼duration-for-uicollectionview-animations –

回答

0

不,沒有辦法自定義由performBatchUpdates引起的動畫的時間。看起來你正試圖在Cell上動畫,特別是在你的collectionview中。爲什麼不使用+(void)animateWithDuration:(NSTimeInterval)持續時間動畫:(void(^)(void))動畫呢?

2

是的你可以改變這個動畫的持續時間。 更改UICollectionViewlayer.speed屬性。

+1

這應該是'layer.speed' - 在這裏討論:http://stackoverflow.com/a/18196592/404525 – Estel

1

只需將其包含在具有所需動畫的 - [UIView animateWithDuration:animations:]塊中即可。這可能不是正確的方式,但它似乎適用於我的iOS 8。

4

有一種方法可以自定義UICollectionView批量更新的持續時間和計時功能。嘗試下面的代碼。這裏是它的外觀https://youtu.be/R0VdC4dliPI

[UIView beginAnimations:nil context:NULL]; 
[UIView setAnimationDuration:0.3]; 

[CATransaction begin]; 
[CATransaction setAnimationDuration:0.3]; 

[CATransaction setAnimationTimingFunction:[CAMediaTimingFunction functionWithControlPoints:0 :1.8 :0 :1]]; 

[self.menuCollectionView performBatchUpdates:^{ 
    [self.menuCollectionView insertItemsAtIndexPaths:@[[NSIndexPath indexPathForItem:index inSection:0]]]; 
    [animatableMenuItems insertObject:@"" atIndex:index]; 
} completion:^(BOOL finished) { 

}]; 

[CATransaction commit]; 
[UIView commitAnimations]; 

https://github.com/DoddaSrinivasan/MultiRowUITabBar

+0

這看起來很棒,很好的代碼。 我玩過這個,如果(像我一樣)你只想改變動畫持續時間或緩解曲線,那麼你可以跳過CATransaction的代碼,只是在開始和結束時使用UIView部分。 – Brett