iPhone 응용 프로그램의 Sony Xperia에서 제공하는 갤러리 응용 프로그램의 기능을 모방하고 싶습니다. 내가 갤러 애플 리케이션, 이미지는 그리드에 날짜별로 그룹화되어 표시되며 섹션의 첫 번째 사진은 다른 것보다 두 배 크기입니다./아웃 곤란에, 모든 사진에서 확대/축소 얻을. Lithu T.V 제안 및 사용자 정의 레이아웃을 만들었습니다으로 UICollectionView/PSTCollectionView의 layoutAttributesForElementsInRect :를 재정 의하여 가시 셀을 다시로드합니다.
나는 PSTCollectionView을 사용했다. 그 레이아웃에서 나는- (NSArray *)layoutAttributesForElementsInRect:(CGRect)rect
을 오버라이드했습니다. Bellow는 같은 코드입니다.
// 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;
}
이 방법이 효과적이고 레이아웃이 원했던 것처럼 보입니다. 이 방법을 사용하면 기본 레이아웃을 사용하면 셀이 더 많이 표시되고 레이아웃은 괜찮아 보입니다. 하지만 아래로 스크롤하면 보이는 셀이 다시로드됩니다. 그 이유는 위임 방법 - (PSUICollectionViewCell *)collectionView:(PSUICollectionView *)cv cellForItemAtIndexPath:(NSIndexPath *)indexPath
이 내 사용자 정의 레이아웃에있는 - (NSArray *)layoutAttributesForElementsInRect:(CGRect)rect
전에 호출되기 때문입니다. 따라서 기본 레이아웃에서는 보이지 않지만 맞춤 레이아웃에서는 보이지 않는 셀은 늦게 다시로드됩니다.
어떻게 이것을 극복 할 수 있습니까?
이 자습서를 참조하십시오 .. http://www.raywenderlich.com/22324/beginning-uicollectionview-in- ios-6-part-12 – Kalpesh
@Kalpesh : 고마워. 앱이 iOS 5에서 작동 할 수 있기 때문에 UICollectionView를 사용할 수 없습니다. PSTCollectionView를 통해 이동하십시오. – Yogi