gpt4 book ai didi

iphone - 覆盖 layoutAttributesForElementsInRect : of UICollectionView/PSTCollectionView causes visible cell to reload

转载 作者:塔克拉玛干 更新时间:2023-11-02 21:41:44 26 4
gpt4 key购买 nike

我想在 iPhone 应用程序中模仿 Sony Xperia 中提供的图库应用程序的功能。我的画廊应用程序,图像按日期分组显示在网格中,该部分的第一张照片是其他照片的两倍。放大/缩小时,所有照片都会缩小/放大。

enter image description here

我按照 Lithu T.V 的建议使用了 PSTCollectionView 并创建了自定义布局。在该布局中,我覆盖了 - (NSArray *)layoutAttributesForElementsInRect:(CGRect)rect。下面是相同的代码。

// called continuously as the rect changes
- (NSArray *)layoutAttributesForElementsInRect:(CGRect)rect {
NSArray *attribs = [super layoutAttributesForElementsInRect:rect];

NSMutableArray *arrmFrames=nil;
for (int i=0;i<attribs.count;i++) {

UICollectionViewLayoutAttributes *attributesInitial=[attribs objectAtIndex:0];

UICollectionViewLayoutAttributes *attributes=[attribs objectAtIndex:i];

//Take initial frame from first cell
if(i==0)
fFirstCellsY = attributes.frame.origin.y;

//while Y is constant, save the adjusted frames for next cells
else if(attributes.frame.origin.y<fFirstCellsY+attributesInitial.frame.size.height)
{
if(arrmFrames==nil)
arrmFrames=[[NSMutableArray alloc]init];

attributes.frame=CGRectMake(attributes.frame.origin.x, attributesInitial.frame.origin.y, attributes.frame.size.width, attributes.frame.size.height);
[arrmFrames addObject:NSStringFromCGRect(CGRectMake(attributes.frame.origin.x, attributes.frame.origin.y+attributes.frame.size.height+10, attributes.frame.size.width, attributes.frame.size.height))];
}

//Adjust the frame of other cells
else
{
CGRect frame = attributes.frame;
attributes.frame=CGRectFromString((NSString*)[arrmFrames objectAtIndex:0]);
[arrmFrames removeObjectAtIndex:0];
[arrmFrames addObject:NSStringFromCGRect(frame)];
}

}

}

return attribs;
}

这行得通,布局看起来就像我想要的那样。通过这种方法,比使用默认布局的单元格更多的单元格变得可见,我的布局看起来不错。但是当我向下滚动时,一些可见的单元格正在重新加载。我想原因是委托(delegate)方法 - (PSUICollectionViewCell *)collectionView:(PSUICollectionView *)cv cellForItemAtIndexPath:(NSIndexPath *)indexPath- (NSArray *)layoutAttributesForElementsInRect:(CGRect )rect 在我的自定义布局中。因此,在默认布局中不可见但在自定义布局中可见的单元格会延迟重新加载。

我怎样才能克服这个问题?

最佳答案

使用UICollectionView如果应用程序应该支持低于 5.0 使用 PSTCollectionView

A nice startup

关于iphone - 覆盖 layoutAttributesForElementsInRect : of UICollectionView/PSTCollectionView causes visible cell to reload,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17917400/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com