获取当前页面 [英] Getting the current page
本文介绍了获取当前页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在我的滚动视图中,我想获取正在显示的当前页面(也许页面不是正确的术语)。我找不到任何保存这个变量。但我认为它必须在某个地方,因为指标能够显示当前正在显示滚动视图的哪个子视图。
这完全隐藏了我们
$ c>属性为当前页。您可以使用以下方法计算: int page = scrollView.contentOffset.x / scrollView.frame.size.width;
如果要向上舍入或向下舍入到最近的页面,请使用:
CGFloat width = scrollView.frame.size.width;
NSInteger page =(scrollView.contentOffset.x +(0.5f * width))/ width;
In my scroll view, I want to get the current page that's being displayed (maybe page isn't the correct term). I can't find any variable that holds this. But I think it must be held somewhere, since the indicator is able to show which sub-view of the scroll view is currently being displayed.
Is this hidden from us completely or is there a way for me to access it?
解决方案
There is no UIScrollView
property for the current page. You can calculate it with:
int page = scrollView.contentOffset.x / scrollView.frame.size.width;
If you want to round up or down to the nearest page, use:
CGFloat width = scrollView.frame.size.width;
NSInteger page = (scrollView.contentOffset.x + (0.5f * width)) / width;
这篇关于获取当前页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文