hpi*_*que 9 iphone uipagecontrol ios ios6 uicollectionview
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水平滚动:
int pages = ceil(self.collectionView.contentSize.width /
self.collectionView.frame.size.width);
Run Code Online (Sandbox Code Playgroud)
如果它垂直滚动:
int pages = ceil(self.collectionView.contentSize.height /
self.collectionView.frame.size.height);
Run Code Online (Sandbox Code Playgroud)
关注维基:
在数学和计算机科学中,floor和ceiling函数分别将实数映射到最大的前一个或最小的下一个整数.更确切地说,floor(x)是不大于x的最大整数,而ceiling(x)是不小于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
Run Code Online (Sandbox Code Playgroud)
如果UICollectionView水平滚动,则将其contentSize宽度除以其框架的宽度:
int pages = floor(self.collectionView.contentSize.width /
self.collectionView.frame.size.width) + 1;
Run Code Online (Sandbox Code Playgroud)
如果它垂直滚动,则将其contentSize高度除以其框架的高度:
int pages = floor(self.collectionView.contentSize.height /
self.collectionView.frame.size.height) + 1;
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
6316 次 |
| 最近记录: |