uiscrollview - 如何在屏幕底部定位 UICollectionViewCell?

标签 uiscrollview uicollectionview uicollectionviewcell

一到三个UICollectionViewCell s 在 UICollectionView .有没有办法在 reloadData 之后始终将单元格定位在屏幕底部?

+----------------+     +----------------+     +----------------+
|                |     |                |     |                |
|                |     |                |     |                |
|                |     |                |     |                |
|                |     |                |     | +------------+ |
|                |     |                |     | |   cell 1   | |
|                |     |                |     | +------------+ |
|                |     | +------------+ |     | +------------+ |
|                |     | |   cell 1   | |     | |   cell 2   | |
|                |     | +------------+ |     | +------------+ |
| +------------+ |     | +------------+ |     | +------------+ |
| |   cell 1   | |     | |   cell 2   | |     | |   cell 3   | |
| +------------+ |     | +------------+ |     | +------------+ |
+----------------+     +----------------+     +----------------+

最佳答案

只需在加载集合 View 后调用以下方法,您就会得到所需的东西。

 - (void)updateContentInset {
        NSInteger numRows = [self collectionView:collectionView numberOfItemsInSection:0];
        CGSize contentInsetTopSize = collectionView.bounds.size;
        CGFloat contentInsetTop = contentInsetTopSize.height;
        int i=0;
        for (i=0;i<numRows;i++) {
            CGFloat height = 70 + [self heightOfTextForString:[arrNotes objectAtIndex:[NSIndexPath indexPathForItem:i inSection:0].row] andFont:[UIFont fontWithName:@"HelveticaNeue-LightItalic" size:13.0] maxSize:CGSizeMake(157, FLT_MAX)];
            contentInsetTop = contentInsetTop - height;

            if (contentInsetTop <=0) {
                contentInsetTop = 0;
                break;
            }
        }

        NSLog(@"Height-->%f",contentInsetTop);
        collectionView.contentInset = UIEdgeInsetsMake(contentInsetTop,0,0,0);

        [NSTimer scheduledTimerWithTimeInterval: 0.01 target: self
                                       selector: @selector(callTheTarget:) userInfo: nil repeats: NO];
    }

关于uiscrollview - 如何在屏幕底部定位 UICollectionViewCell?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26943299/

相关文章:

ios - 遍历 UICollectionView 中的所有单元格

ios - 在多个 Collection View 中重用单个 UICollectionViewCell

swift - UICollectionViewCell 协议(protocol)不起作用

ios - 如何在 Swift 中重置 UICollectionView

ios - 有没有办法在 UIScrollView 中隐藏滚动指示器?

ios - 将 UIScrollView 放在 UIPageView 中,滚动不起作用

ios - 这是什么?带有 subview Controller 的 ContainerView 的 UITableView?

ios - UICollectionView 显示多种尺寸的单元格?

uitableview - UITableViewCell 动态布局中的 Swift UICollectionView 无法更改单元格高度

ios - 缩小放置在 UIScrollView 中的 UIImageView