에서 작업중인 경우 & 머리글 상자가 UICollectionView
에 들어가는 위치를 어떻게 지정합니까?iOS UICollectionView 머리글 및 바닥 글 위치
저는 UICollectionViewFlowLayout
입니다. 내가 덮어 썼다
-(void)prepareLayout
-(NSArray*) layoutAttributesForElementsInRect:(CGRect)rect
-(UICollectionViewLayoutAttributes*) layoutAttributesForSupplementaryViewOfKind: (NSString*)kind atIndexPath:(NSIndexPath*)indexPath
내 문제는, 어떻게 헤더 위치를 지정 해야할지 모르겠다. 이미 헤더가 prepareLayout
에 있는지 지정한 :
-(void)prepareLayout
{
[super prepareLayout];
boundsSize = self.collectionView.bounds.size;
midX = boundsSize.width/2.0f;
curIndex = 0;
self.headerReferenceSize = CGSizeMake(CELL_SIZE, TITLE_HEIGHT);
self.footerReferenceSize = CGSizeMake(0, 0);
self.scrollDirection = UICollectionViewScrollDirectionHorizontal;
self.sectionInset = UIEdgeInsetsMake(TOP_INSET, LEFT_INSET, BOTTOM_INSET, RIGHT_INSET);
self.minimumLineSpacing = LINE_SPACING;
self.minimumInteritemSpacing = INTERIM_SPACING;
self.itemSize = CGSizeMake(CELL_SIZE, CELL_SIZE);
}
설정 "HeaderLocation"처럼 뭔가있을 것 같지 않기 때문에 난 그냥,
FlowLayout
설정하는 내 사용자 지정의 오른쪽 속성을 모르는
, LayoutAttributes 또는 레이아웃 객체 자체로 나타납니다. 바로 지금, 그것은 내 이미지들 사이에/그들이 각 이미지 (수평 스크롤) 위에 나타나기를 바랄 때 나타나는 것입니다.
-(UICollectionReusableView*) collectionView: (UICollectionView*)collectionView viewForSupplementaryElementOfKind:(NSString*)kind atIndexPath:(NSIndexPath*)indexPath
{
NSLog(@"**ViewForSupplementaryElementOfKind called***");
CGFloat centerX = collectionView.center.x;
CGFloat centerY = collectionView.center.y;
CGFloat titleWidth = [MyLayout titleWidth];
CGFloat titleHeight = [MyLayout titleHeight];
MyTitleView* titleView = [collectionView dequeueReusableSupplementaryViewOfKind:kind withReuseIdentifier:ImageTitleIdentifier forIndexPath:indexPath];
titleView.frame = CGRectMake(centerX - titleWidth/2.0,
0.0,
titleWidth,
titleHeight);
return titleView;
}
이 작동하지 않습니다
나는 다음과 같은 노력했다. 제목이 다른 제목들과 겹쳐진 위에 나타납니다. 그런 다음 스크롤을 시작한 후 (가로로), 위의 이미지가 아닌 이미지 사이에 잘못된 위치로 다시 건너 뜁니다.
PS> NIB 또는 XIB 게재 위치와 관련된 사항을 제안하지 마십시오. UICollectionView를 사용하고 UICollectionViewController가 아니므로 실제로 프로토 타입 셀을 사용할 필요가 없습니다. 레이아웃은 코드만으로 프로그래밍 방식으로 진행되고 있으므로 XIB 파일을 열고 텍스트 상자의 위치를 조정할 수는 없습니다.
감사합니다,하지만 난 이미 높이를 변경하는 방법을 알고, 내가 어디에 위치를 변경하는 방법을 알고 싶습니다. 에서와 같이 y 좌표 = 0에서 내 헤더보기를 내용 위에 배치하도록 프로그램에 지시하고 싶습니다. 솔루션에서 명확하게 특정 위치에 배치 할 헤더를 말하고 있습니까? dequeueReusableSupplementaryView는 저를 제어 할 수 없습니다. – Cindeselia
"MyTitleView"란 무엇입니까? 수업입니까? –
예, 내 머리글 클래스입니다. – Cindeselia