얘들 아 ... 나는 셀 의 제목과 레이블을 포함 5 개 세포를 UICollectionView를 통해 사용자 지정 컨트롤 세그먼트 ..UICollectionView가 인덱스로 스크롤 했습니까? 나는 당신의 도움이 필요
CustomView.m
을 생성 I이 방법에 sizeForItemAtIndexPath 방법을 구현 UILabel의 폭에 의해 셀 폭을 얻을 :
-(CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
CGSize size = [[[self titleSection] objectAtIndex:indexPath.item] sizeWithAttributes:nil];
return CGSizeMake(size.width +35 , self.frame.size.height);
}
제가 또한 선택되어있는 셀 나타내는 커서 기능을 갖는 UIView의 생성. 내가 가진 인덱스 경로를 공유하는 수평 스크롤 또 다른 UICollectionView가 다른의 ViewController 지금
-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
NSIndexPath *newIndexPath = [NSIndexPath indexPathForItem:indexPath.item inSection:0];
[collectionView scrollToItemAtIndexPath:newIndexPath atScrollPosition:UICollectionViewScrollPositionCenteredHorizontally animated:YES];
UDPassData *data = [UDPassData sharedInstance];
[data.sectionContentCollection scrollToItemAtIndexPath:newIndexPath atScrollPosition:UICollectionViewScrollPositionNone animated:YES];
if (indexPath == newIndexPath) {
[collectionView scrollToItemAtIndexPath:indexPath atScrollPosition:UICollectionViewScrollPositionCenteredHorizontally animated:YES];
}
UICollectionViewLayoutAttributes *attributes = [collectionView layoutAttributesForItemAtIndexPath:newIndexPath];
CGRect cellFrameInSuperview = [collectionView convertRect:attributes.frame toView:collectionView];
data.index = cellFrameInSuperview;
[UIView animateWithDuration:.4 delay:0 usingSpringWithDamping:1 initialSpringVelocity:1 options:UIViewAnimationOptionCurveEaseInOut animations:^{
_horizontalBar.frame = CGRectMake(cellFrameInSuperview.origin.x, _horizontalBar.frame.origin.y, cellFrameInSuperview.size.width , 3);
} completion:nil];
}
UICollectionViewController.m
: 내가 구현이 방법으로 커서 (UIView의를) 애니메이션 세그먼트 컨트롤을 사용하여 customView 컨트롤을 사용하여 collectionView의 스크롤을 제어 할 수 있습니다. 여기까지 모든 것이 작동하지만 모든 것을 얻을 수 있었지만 문제가 생겼습니다.
uicollection보기가 스크롤 될 때 세그먼트 컨트롤 슬라이더가 움직이지 않습니다 ... 간단히 말해서, collectionView가 셀 2에 있으면 맞춤 세그먼트 컨트롤 커서는 내가 만든 세그먼트 컨트롤의 두 번째 셀로 이동해야합니다.
편집을 설명 할 수 : 내가 얻으려고 어떤 것은 내가 유튜브 응용 프로그램에서 본적이 있습니다. 상단 메뉴 ...
나는 2 collectionView와 함께이 일을하고 있습니다.
첫 collectionView 두 번째 collectionView이 페이지 사이를 탐색하고하기 위해 reload
collectionView 데이터 소스에
저는 제로의 속도를 지켜봐야 할 것이라고 확신합니까? – Fattie
당신이 무슨 뜻인지 이해가 안 돼요 ... 다른 클래스의 일부인 scrollViewDidScroll 함수를 통해 세그먼트 컨트롤 슬라이더를 제어하는 방법을 모르겠다 – kAiN
내가 당신의 문제를 이해했는지 모르겠지만'didScroll : 'UICollectionView' 델리게이트 (상속받은 'UIScrollView' 또는 다른 적절한'UIScrollViewDelegate' 메쏘드)를 상속 받았을 때, 당신이 스크롤했을 때 다른 것을 스크롤하거나 변경할 수 있습니다. – Larme