iOS:具有无限分页的滚动视图的索引页
我有这个代码: 对于 3 个滚动视图来说,有一个随机分页,
CGRect frame = scrollView.frame;
CGRect frame1 = scrollView1.frame;
CGRect frame2 = scrollView2.frame;
frame.origin.x = frame.size.width * (arc4random() % (arrayimage.count ));
frame.origin.y = 0;
frame1.origin.x = frame.size.width * (arc4random() % (arrayimage.count ));
frame1.origin.y = 0;
frame2.origin.x = frame.size.width * (arc4random() % (arrayimage.count ));
frame2.origin.y = 0;
int pageFirst = scrollView.contentOffset.x/scrollView.frame.size.width;
int pageSecond = scrollView1.contentOffset.x/scrollView1.frame.size.width;
int pageThird = scrollView2.contentOffset.x/scrollView2.frame.size.width;
我的问题是,当我启动我的应用程序时,pageFisrt、pageSecond 和 PageThird 的 nslog 值始终相等,但分页是随机且不同的;如何获得 pagefirst、pageSecond 和 pageThird 的正确值?
I have this code:
it's for 3 scroll view to have a random paging
CGRect frame = scrollView.frame;
CGRect frame1 = scrollView1.frame;
CGRect frame2 = scrollView2.frame;
frame.origin.x = frame.size.width * (arc4random() % (arrayimage.count ));
frame.origin.y = 0;
frame1.origin.x = frame.size.width * (arc4random() % (arrayimage.count ));
frame1.origin.y = 0;
frame2.origin.x = frame.size.width * (arc4random() % (arrayimage.count ));
frame2.origin.y = 0;
int pageFirst = scrollView.contentOffset.x/scrollView.frame.size.width;
int pageSecond = scrollView1.contentOffset.x/scrollView1.frame.size.width;
int pageThird = scrollView2.contentOffset.x/scrollView2.frame.size.width;
my problem is that when I launch my app nslog values for pageFisrt, pageSecond and PageThird is ever equal but paging is random and different; how can I have the correct value of pagefirst, pageSecond and pageThird?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您正在设置 3 个滚动视图的框架,这会将 3 个滚动视图放置在其超级视图中的随机位置 - 这不会影响 contentOffset。
看起来你想做的是
scrollView.contentOffset = (CGPoint){scrollView.bounds.size.width * (arc4random() % (arrayimage.count )), 0};
You are setting the frame of your 3 scroll views which will position the 3 scrollViews at random places in their superview - this does not affect the contentOffset.
It looks as though what you meant to do was
scrollView.contentOffset = (CGPoint){scrollView.bounds.size.width * (arc4random() % (arrayimage.count )), 0};