2013-04-17 2 views
45

UICollectionView은 현재 6 개 항목을 제공하는 UICollectionViewDataSource으로 설정되어 있습니다. 화면 채우기에 필요한 것보다 적습니다. 문제는 화면을 채울 수있는 항목이 충분할 때만 (10, 20으로 테스트 한 경우) 컬렉션보기가 스크롤된다는 것입니다. 더 적은 수의 아이템을 표시 할 때, 나는이 바운스 애니메이션을 얻지 못할 것입니다.UICollectionView가 스크롤되지 않습니다.

- (void)viewWillAppear:(BOOL)animated 
{ 
    [super viewWillAppear:animated]; 

    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(updateCollectionViewData) name:UIDocumentStateChangedNotification object:nil]; 

    UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc]init]; 
    flowLayout.itemSize = CGSizeMake(160, 100); 
    flowLayout.minimumInteritemSpacing = 0; 
    flowLayout.minimumLineSpacing = 0; 

    self.collectionView = [[UICollectionView alloc]initWithFrame:self.view.bounds collectionViewLayout:flowLayout]; 
    [self.collectionView registerClass:[UICollectionViewCell class] forCellWithReuseIdentifier:@"Cell"]; 
    self.collectionView.delegate = self; 
    self.collectionView.dataSource = self; 
    self.collectionView.bounces = YES; 
    [self.view addSubview:self.collectionView]; 
} 

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section { 
    return [self.collectionViewData count]; 
} 
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath 
{ 
    UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"Cell" forIndexPath:indexPath]; 

    Expense *expense = [self.collectionViewData objectAtIndex:indexPath.row]; 

    UILabel *label = [[UILabel alloc]initWithFrame:cell.bounds]; 
    label.text = expense.value; 
    label.backgroundColor = [UIColor clearColor]; 
    label.font = [UIFont fontWithName:@"Miso-Bold" size:30]; 
    label.textAlignment = NSTextAlignmentCenter; 
    [cell addSubview:label]; 

    cell.backgroundColor = [UIColor colorWithRed:1 - (indexPath.row/30.0f) green:0 blue:1 alpha:1]; 

    return cell; 
} 

도움 주셔서 감사합니다.

답변

151

bounces은 이름에도 불구하고 설정할 수있는 적절한 속성이 아닙니다. alwaysBounceVertical 및/또는 alwaysBounceHorizontal도 설정해야합니다. 문서에서 :

이 속성이 YES와 반송로 설정되어있는 경우 YES, 수직 드래그는 내용이 스크롤 뷰의 경계보다 작은 경우에도 을 허용한다. 기본값은 NO입니다.


주 IB의 혼란 이름 .. 콜렉션 뷰 "반송"와 "반송 수직"에 대한 속성 관리자의 스토리 보드와 https://stackoverflow.com/a/18391029/294884

+0

이것은 올바른 대답입니다. OP는 이것을 대답으로 받아 들여야합니다. –

+0

위대한 팁 감사합니다 – Fattie

+0

고마워요, 그것은 매력처럼 작동합니다 :) – evya

4

크기의 UICollectionView 높이를 설정하면 스크롤링 문제가 비활성화됩니다. UICollectionView의 키가 568 픽셀이면 568 픽셀 이상의 콘텐츠가있는 경우 스크롤해야합니다. 포함 된 뷰의 높이로 설정해야합니다 (너비와 동일).

희망이 있으면 도움이됩니다.

+0

UICollectionView 가장자리를 슈퍼 뷰 가장자리와 동일하게 유지하기 위해 IB에 제약 조건을 추가했습니다. – Colin

9

은 확인해야합니다.

관련 문제