2013-07-29 2 views
2

iPhone 응용 프로그램의 Sony Xperia에서 제공하는 갤러리 응용 프로그램의 기능을 모방하고 싶습니다. 내가 갤러 애플 리케이션, 이미지는 그리드에 날짜별로 그룹화되어 표시되며 섹션의 첫 번째 사진은 다른 것보다 두 배 크기입니다./아웃 곤란에, 모든 사진에서 확대/축소 얻을. Lithu T.V 제안 및 사용자 정의 레이아웃을 만들었습니다으로 UICollectionView/PSTCollectionView의 layoutAttributesForElementsInRect :를 재정 의하여 가시 셀을 다시로드합니다.

enter image description here

나는 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 전에 호출되기 때문입니다. 따라서 기본 레이아웃에서는 보이지 않지만 맞춤 레이아웃에서는 보이지 않는 셀은 늦게 다시로드됩니다.

어떻게 이것을 극복 할 수 있습니까?

+0

이 자습서를 참조하십시오 .. http://www.raywenderlich.com/22324/beginning-uicollectionview-in- ios-6-part-12 – Kalpesh

+0

@Kalpesh : 고마워. 앱이 iOS 5에서 작동 할 수 있기 때문에 UICollectionView를 사용할 수 없습니다. PSTCollectionView를 통해 이동하십시오. – Yogi

답변

1

사용 UICollectionView 응용 프로그램 미만 5.0 사용을 지원하도록되어있는 경우 PSTCollectionView

A nice startup

+0

응답 해 주셔서 감사합니다. 나는 튜토리얼을 통해 갔고 실제로 유망 해 보인다. 하나의 쿼리 만 UICollectionView/PSTCollectionView를 사용하여 집기를 사용하여 이미지를 확대/축소 할 수 있습니까? – Yogi

+0

나는 그것들이 존재하지만 포함될 수 있다고 생각하지 않는다. 실제로 탭을위한 메서드가 있지만, 꼬집음을 설정할 수있다. –

+0

고맙습니다. 다시로드하는 동안 깜박일 수 있으므로 컬렉션 뷰를 깜박이지 않고 부드럽게 수행 할 수 있습니까? – Yogi

관련 문제