Make UIScrollView wrap around(使 UIScrollView 环绕)
问题描述
可能重复:
UIScrollView.关于实施无限"的任何想法滚动/缩放?
我有一个有八页左右的 UIScroll.我的目标是让他们循环",以便当用户到达最后一页时,第一页将是下一页(反之亦然),以便用户可以无休止地滚动页面.实现这一目标的最佳方法是什么?
I have a UIScroll which has eight or so pages. My aim is for them to 'loop' around so that when the user reaches the last page the first page will be the next page (and vice versa) so that the user could scroll through the pages endlessly. What is the best way to achieve this?
我正在使用这个 示例 来自可可与爱.
I am working from this example from Cocoa with Love.
非常感谢任何帮助.谢谢.
Any help is greatly appreciated. Thank you.
推荐答案
问题已经解决.基本上,我在页面之前和之后创建了额外的页面,所以它看起来像这样:
Problem is sorted now. Basically, I created extra pages before and after my pages so it looks like this:
8 1 2 3 4 5 6 7 8 1
8 1 2 3 4 5 6 7 8 1
然后在 scrollViewDidEndDecelerating
我执行一个简单的 if 语句来检查我是在第一页还是最后一页并适当地找到 scrollView
.
Then in the scrollViewDidEndDecelerating
I do a simple if statement that checks if I am at either the first or last page and locate the scrollView
appropriately.
- (void)scrollViewDidEndDecelerating:(UIScrollView *)newScrollView
{
[self scrollViewDidEndScrollingAnimation:newScrollView];
pageControl.currentPage = currentPage.pageIndex;
if(currentPage.pageIndex==0){
scrollView.contentOffset = CGPointMake(320*(pageControl.numberOfPages-2), 0);
pageControl.currentPage = pageControl.numberOfPages-2;
}else if(currentPage.pageIndex==pageControl.numberOfPages-1){
scrollView.contentOffset = CGPointMake(320, 0);
pageControl.currentPage = 1;
}
}
这篇关于使 UIScrollView 环绕的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:使 UIScrollView 环绕


- android 4中的android RadioButton问题 2022-01-01
- MalformedJsonException:在第1行第1列路径中使用JsonReader.setLenient(True)接受格式错误的JSON 2022-01-01
- 想使用ViewPager,无法识别android.support.*? 2022-01-01
- 使用自定义动画时在 iOS9 上忽略 edgesForExtendedLayout 2022-01-01
- 用 Swift 实现 UITextFieldDelegate 2022-01-01
- 如何检查发送到 Android 应用程序的 Firebase 消息的传递状态? 2022-01-01
- Android - 我如何找出用户有多少未读电子邮件? 2022-01-01
- 在测试浓缩咖啡时,Android设备不会在屏幕上启动活动 2022-01-01
- Android viewpager检测滑动超出范围 2022-01-01
- Android - 拆分 Drawable 2022-01-01