为什么layoutAttributesForItemAtIndexPath中的属性属性未应用?

时间:2014-11-19 13:00:56

标签: ios objective-c iphone uicollectionview uipangesturerecognizer

如果我修改了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只要我拖动就被调用,但属性不会被应用。

1 个答案:

答案 0 :(得分:0)

你应该再覆盖一个方法:

- (NSArray *)layoutAttributesForElementsInRect:(CGRect)rect
{

{