【发布时间】:2012-10-11 13:25:09
【问题描述】:
我在 UICollectionView 中显示了许多图像单元格。 通过一个按钮,我希望能够将我的所有单元格分组到第一个按钮上。
这运行良好,但是当我尝试将动画过渡添加到我的重组动作时,没有任何反应。
这是我在自定义布局中使用的方法:
- (NSArray*)layoutAttributesForElementsInRect:(CGRect)rect
{
NSArray* allAttributesInRect = [super layoutAttributesForElementsInRect:rect];
if([allAttributesInRect count] > 0 && _isRegroup)
{
UICollectionViewLayoutAttributes *firstAttribute = [allAttributesInRect objectAtIndex:0];
CGRect frame = firstAttribute.frame;
for(UICollectionViewLayoutAttributes *attribute in allAttributesInRect)
[UIView animateWithDuration:0.3f animations:^{attribute.frame = frame;}];
}
return allAttributesInRect;
}
- (void)regroupCells:(BOOL)isRegroup // This method is called from my collection controller when my button is pressed
{
_isRegroup = isRegroup;
[self invalidateLayout];
}
有什么想法吗? 谢谢!
【问题讨论】:
标签: ios animation layout uicollectionview