2013-09-10 3 views
1

JSON을 사용하여 채워진 UICollectionView가 있습니다. 영화 포스터가있는 커버 플로우 스타일의 레이아웃입니다.UICollectionView : 화면 위치에서 셀 가져 오기

화면의 특정 지점에 셀의 제목 속성을 표시하여 가로로 스크롤하면 가운데에 보이는 셀의 제목이 표시되는지 궁금합니다.

나는 indexPathForItemAtPoint를 사용해 보았지만, 그 점은 항상 동일한 인덱스를 표시하는 콜렉션 뷰로 스크롤하는 것처럼 보인다.

편집 : 추가하는 코드 :

UIView *test = [[UIView alloc] initWithFrame:CGRectMake(10, 30, self.view.frame.size.width+180, 390)]; 
test.backgroundColor = [UIColor clearColor]; 
superView.backgroundColor = [UIColor blackColor]; 


PerspectiveFlowLayout *layout = [[PerspectiveFlowLayout alloc]init]; 
self.boxes.bounces = NO; 

BoxView *boxes = [[BoxView alloc] initWithFrame:test.frame collectionViewLayout:layout]; 


[test addSubview:boxes]; 
[superView addSubview: test]; 
NSIndexPath *path = [self.boxes indexPathForItemAtPoint:[self.boxes convertPoint:CGPointMake(100.0, 100.0) toView:[self.boxes superview]]]; 

Cell *atpoint = [self.boxes cellForItemAtIndexPath:path]; 


NSLog(@"%@", atpoint.model.name); 

이 도와 주셔서 너무 감사 로건

+0

사용중인 코드를 붙여 넣을 수 있습니까? indexPathForItemAtPoint가 문제를 해결해야합니다. 아마도 하위 뷰에서 잘못된 Point 좌표를 사용하고있을 것입니다. 어떤 곳에서든 convertPoint를 사용하고 있습니까? –

+0

나는 UICollectionView를 UIView의 서브 뷰로, 그리고 페이지의 중간에 위치한다. 가로로 스크롤합니다. 나는했다 : NSIndexPath * 경로 = [self.boxes indexPathForItemAtPoint : CGPointMake (100.0, 300.0)]; –

+0

실제로 첫 번째 포스터를 반환하지만 스크롤 할 때마다 첫 번째 포스터가 호출 될 때마다 계속 반환합니다. –

답변

0

당신이 변환 포인트를 할 때부터 진행되어 그 항목의 라운드를 교환하십시오 컬렉션보기의 수퍼 뷰 :

NSIndexPath *path = [self.boxes indexPathForItemAtPoint:[[self.boxes superview] convertPoint:CGPointMake(100.0, 100.0) toView:self.boxes]];