문제

내가 사용하는 UICollectionView 프로그래밍 방식으로 보여줍니다.

나는 설정의 구조는 다음과 같다:

UICollectionView *collectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(0, 100, self.view.frame.size.width, 3000) collectionViewLayout:flowLayout];

UICollectionViewFlowLayout 섹션이 있 삽입식으로 설정:

flowLayout.sectionInset = UIEdgeInsetsMake(20.0, 20.0, 100.0, 20.0);

또한 단지 1 섹션입니다.

나의 높이를 설정할 3,000 하십시오 컬렉션 뷰 스크롤 하지만 그렇지 않습니다.나는 그것을 설정하는 이 컬렉션을 볼 것 같지 않나 아래로 스크롤을 때에 삽입하는 새로운 항목입니다.

UICollectionView 하위에서 UIScrollView, 을 의미할 수 있습니다 다시 스크롤 콘텐츠를 볼 크기입니다.는 것 이것이 제대로 작동?

만 문제는 이 일을 알고 있는 경우는 크기의 모든 항목을 포함하여 어떻게 많은에 항목이 각각의 행이 있습니다.

면 각 항목이 있었 다른 크기로,어떻게 찾을 밖으로 크기를 각각의 행?를 필요가 있는 추가 모든 행 크기와 증가 콘텐츠 크기의 높이 self.collectionView.

편집

심지어 내 제안은 위의,재설정 내용의 크기,제대로 작동하지 않!나 업데이트할 때 다음 내 컬렉션 view:

 int numberOfRows = self.dataArray.count / 3;
self.collectionView.contentSize = CGSizeMake(self.view.frame.size.width, (numberOfRows * 200) + 300);

이것은 매우 못생긴 하지만입니다.이 때문에서 나의 모든 이미지의 크기 200x200px 맞는 3 개의 이미지 행당(따라서 사단에 의해 3).

또한,심지어+300 가,마지막 줄 수 있만 참조하십시오 3/4 그것의 모든지 않습니다.가 더 나는 볼 수 있지만 그것은 다시 다시 3/4.그와 같은 종류의 스크롤 새로 고침하는 곳,보기만 이동하는 경우에 당신은 그것을 끌어를 떠날 때 그것을 혹시 어디 있었다.왜 이런 일이 무엇입니까?그것은 단지는 애플의 설계 UICollectionView 그래서 가난하게?이것은 작은 말도...UITableViews 조정이 그들의 스크롤 그 내용에 따라 자동으로 합니다.

도움이 되었습니까?

해결책

에서 응답의 일부를 다른 질문들에 대한 UICollectionView 을 만들고,이 데모 프로젝트와 스크롤 그냥 좋은,그래서 모르겠어 문제가 있다.유일한 것은 내가해야 할 필요한을 마지막 행 전체적으로 보이던 크기를 늘리의 하단에 삽입된 90.또한 추가 완료 방법 performBatchUpdates:료:자동으로 스크롤 그래서 마지막으로 추가된 항목은 표시(예를 추가 몇 가지 추가 항목을 사용하여 performSelector;withObject:afterDelay:).이미지 48x48,그리고 나는 단지 설정 내 컬렉션 보기 범위 내 컨트롤러 보기입니다.는 코드는 다음과 같습니다 비교할 수 있습니다 그래서 당신은 그것을 당신이 무엇:

@interface ViewController () <UICollectionViewDataSource, UICollectionViewDelegateFlowLayout> {
NSMutableArray *newData;
}
 @property (nonatomic, retain) UICollectionView *collectionView;
 @property (nonatomic, retain) NSMutableArray *results;
 @end

@implementation ViewController

- (void)viewDidLoad {
    self.results = [NSMutableArray array];
    int i = 11;
    while (i<91) {
        UIImage *image = [UIImage imageNamed:[NSString stringWithFormat:@"New_PICT00%d.jpg",i]];
        [self.results addObject:image];
        i++;
    }

    UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc] init];
    //flowLayout.scrollDirection =  UICollectionViewScrollDirectionHorizontal;

    self.collectionView = [[UICollectionView alloc] initWithFrame:self.view.bounds collectionViewLayout:flowLayout];
    self.collectionView.dataSource = self;
    self.collectionView.delegate = self;
    self.view.backgroundColor = [UIColor blackColor];
    [self.view addSubview:self.collectionView];
    [self.collectionView registerClass:[UICollectionViewCell class] forCellWithReuseIdentifier:@"Cell"];
    //[self.collectionView registerClass:[RDCell class] forCellWithReuseIdentifier:@"myCell"];
    [self.collectionView reloadData];

    [self performSelector:@selector(addNewImages:) withObject:nil afterDelay:3];
}

-(void)addNewImages:(id)sender {
    newData = [NSMutableArray array];
    int i = 102;
    while (i<111) {
        UIImage *image = [UIImage imageNamed:[NSString stringWithFormat:@"New_PICT0%d.jpg",i]];
        [newData addObject:image];
        i++;
    }
    [self addNewCells];
}

-(void)addNewCells {
    NSMutableArray *arrayWithIndexPaths = [NSMutableArray array];
    [self.collectionView performBatchUpdates:^{
        int resultsSize = [self.results count];
        [self.results addObjectsFromArray:newData];
        for (int i = resultsSize; i < resultsSize + newData.count; i++)
            [arrayWithIndexPaths addObject:[NSIndexPath indexPathForRow:i inSection:0]];
        [self.collectionView insertItemsAtIndexPaths:arrayWithIndexPaths];
    }
    completion: ^(BOOL finished){
        [self.collectionView scrollToItemAtIndexPath:arrayWithIndexPaths.lastObject atScrollPosition:UICollectionViewScrollPositionCenteredVertically animated:YES];
    }];
}


- (NSInteger)collectionView:(UICollectionView *)view numberOfItemsInSection:(NSInteger)section {
    return [self.results count];
}

- (NSInteger)numberOfSectionsInCollectionView: (UICollectionView *)collectionView {
    return 1;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"Cell" forIndexPath:indexPath];
    //cell.iv.image = [self.results objectAtIndex:indexPath.row];
    cell.backgroundColor = [UIColor colorWithPatternImage:[self.results objectAtIndex:indexPath.row]];
    return cell;
}


- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
    UIImage *image = [self.results objectAtIndex:indexPath.row];
    return CGSizeMake(image.size.width, image.size.height);
}

- (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout insetForSectionAtIndex:(NSInteger)section {
    return UIEdgeInsetsMake(10, 10, 90, 10);
}

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
    NSLog(@"Selected Image is Item %d",indexPath.row);
}

다른 팁

설정의 높이 UICollectionView 3000 만들 것입니다 당신의 스크롤 문제를 악화됩니다.는 경우 UICollectionView 3000 픽셀 높이 다음 그것만 스크롤해야 할 경우 이상 3000 픽셀의 콘텐츠에습니다.설정해야 합니다 그것의 높이 뷰에서 포함(과 같은 폭).

AFAIK 또한 설정하지 않아야 합니다 contentSize 직접 대신에,당신은 필요한 재정의 - (CGSize)collectionViewContentSize 메서드에 하위 클래스 UICollectionViewLayout, 하지만,일반적으로 말하기를 변경할 필요가 없는 콘텐츠 크기 위해 정상적인 사용합니다.

나는 완전히 명확하지 않에 무엇이 문제입니다-그것은 추가할 때보다 더 많은 화면의 가치가 항목할 수 없습니다 스크롤?

나는 같은 문제가 발생했었기 때문에 초기화 요소의 내 collectionView(i.e그것은 DataSource)에 viewWillAppear 방법입니다.

마지막으로 추가 [self.collectionView reloadData]; 만 괜찮습니다!

어쩌면 당신은에서 동일한 경우입니다.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top