在iOS中使用分页的UICollectionView的页数 [英] Page count of UICollectionView with paging in iOS
问题描述
考虑启用流布局和分页的 UICollectionView
(通过将 pagingEnabled
设置为 YES
)。
Consider a UICollectionView
with flow layout and paging enabled (by setting pagingEnabled
to YES
).
获取总页数的最简单方法是什么?
What would be the simplest way of obtaining the total number of pages?
哪里是最适合更新页面总数的地方(如果添加/删除项目可能会更改,集合视图的大小会更改或布局更改)?
And where would be the most appropriate place to update the total number of pages (given that it might change if items are added/deleted, the size of the collection view changes or the layout changes)?
推荐答案
正确的答案应该是:
如果是UICollectionView水平滚动:
If the UICollectionView scrolls horizontally:
int pages = ceil(self.collectionView.contentSize.width /
self.collectionView.frame.size.width);
如果它垂直滚动:
If it scrolls vertically:
int pages = ceil(self.collectionView.contentSize.height /
self.collectionView.frame.size.height);
关注 wiki :
在数学和计算机科学中,地板和天花板功能
map
整数之后的最大前一个或最小的实数。更准确地说,floor(x)是
不大于x的最大整数,而ceiling(x)
是不小于x的最小整数。
In mathematics and computer science, the floor and ceiling functions map a real number to the largest previous or the smallest following integer, respectively. More precisely, floor(x) is the largest integer not greater than x and ceiling(x) is the smallest integer not less than x.
这是我要检查的结果:
ceil(2.0/5.0) = 1.000000
ceil(5.0/5.0) = 1.000000
ceil(6.0/5.0) = 2.000000
ceil(10.0/5.0) = 2.000000
ceil(11.0/5.0) = 3.000000
这篇关于在iOS中使用分页的UICollectionView的页数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!