我正在使用ScrollView。在我的滚动视图中有收藏夹视图。我的收藏视图的最后3个元素隐藏在空白内。滚动ScrollView时不显示,而滚动CollectionView时显示。我想在滚动ScrollView上显示所有收集的单元格。不滚动CollectionView。

-(NSInteger)numberOfSectionsInCollectionView:
(UICollectionView *)collectionView {

    return 1; // The number of sections we want
}
-(NSInteger)collectionView:(UICollectionView *)collectionView
    numberOfItemsInSection:(NSInteger)section {

    return 5; // the number of cells we want
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionViewd
                  cellForItemAtIndexPath:(NSIndexPath *)indexPath {

    CollectionCell* cell =
    [collectionViewd dequeueReusableCellWithReuseIdentifier:@"collectionView2CellIdentifier"
                                               forIndexPath:indexPath]; // Create the cell from the storyboard cell

    cell.layer.cornerRadius = 4;
    cell.layer.borderWidth = 1;
    cell.layer.borderColor = [UIColor grayColor].CGColor;

    cell.yellow.layer.cornerRadius=4;
    cell.red.layer.cornerRadius=4;


    cell.title.text =[titleArray objectAtIndex:indexPath.row];
    cell.date.text =[dateArray objectAtIndex:indexPath.row];
    cell.incomeText.text =[netIncomeArray objectAtIndex:indexPath.row];
    cell.expenseText.text =[netExpenseArray objectAtIndex:indexPath.row];
     cell.saving.text =[savingArray objectAtIndex:indexPath.row];
    cell.expensePecentageText.text =[expensePercentage objectAtIndex:indexPath.row];
    cell.savingPercentage.text =[netProfitPercentage objectAtIndex:indexPath.row];

    return cell; // Return the cell
}

- (CGFloat)collectionView:(UICollectionView *) collectionView
                   layout:(UICollectionViewLayout *) collectionViewLayout
minimumInteritemSpacingForSectionAtIndex:(NSInteger) section {
    return 2.0;
}


- (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout insetForSectionAtIndex:(NSInteger)section
{
    return UIEdgeInsetsMake(2, 2, 2, 2);
}
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
{

    return CGSizeMake(155, 158);

}
    [scrollView setContentSize:CGSizeMake(0, expenseButton.frame.origin.y+expenseButton.frame.size.height+collection.frame.size.height+16)];

最佳答案

首先计算collectionview的高度

例如

titleArray.count * 160(158px的单元格高度+ 2px的单元格空间)

然后将此高度分配给collectionview框架

还将其分配给scrollview内容大小高度。

这肯定会为您解决问题。

10-08 09:29
查看更多