如果我修改了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;
}
我正在UIPanGestureRecognizer
申请UICollectionView
,我想申请这些
当前正在拖动的单元格上的属性。
我可以在调用此方法的同时调用layoutAttributesForItemAtIndexPath方法:
[customLayoutInstance indexOfItemSelected:indexPath.row];
layoutAttributesForItemAtIndexPath
只要我拖动就被调用,但属性不会被应用。
答案 0 :(得分:0)
你应该再覆盖一个方法:
- (NSArray *)layoutAttributesForElementsInRect:(CGRect)rect
{
{