【发布时间】:2014-11-19 13:00:55
【问题描述】:
如果我修改了layoutAttributesForItemAtIndexPath 中的任何属性属性,collectionView 单元格不会被修改
- (UICollectionViewLayoutAttributes *)layoutAttributesForItemAtIndexPath:(NSIndexPath *)indexPath
{
UICollectionViewLayoutAttributes *attributes = [super layoutAttributesForItemAtIndexPath:indexPath];
//this properties does not get applied
attributes.zIndex = 1;
attributes.alpha = 0.5;
return attributes;
}
但是当将属性修改移动到layoutAttributesForElementsInRect 时,它会被应用:
- (NSArray *)layoutAttributesForElementsInRect:(CGRect)rect
{
NSArray *attributesArray = [super layoutAttributesForElementsInRect:rect];
for (UICollectionViewLayoutAttributes *attributes in attributesArray)
{
//this properties is getting applied here
attributes.zIndex = 1;
attributes.alpha = 0.5;
}
return attributesArray;
}
我在UICollectionView 上应用UIPanGestureRecognizer,我想应用这些
我当前正在拖动的单元格的属性。
我可以在拖动调用此方法时调用 layoutAttributesForItemAtIndexPath 方法:
[customLayoutInstance indexOfItemSelected:indexPath.row];
只要我在拖动,就会调用layoutAttributesForItemAtIndexPath,但不会应用属性。
【问题讨论】:
标签: ios objective-c iphone uicollectionview uipangesturerecognizer