对于右端,请尝试减小滚动视图的属性的宽度,以使滚动视图在到达最后一页之前停止分页。 对于左端,将每页的frame.origin.x
属性减少相同的数量。前几页在滚动视图中会有一个负x位置。
本质上,使滚动视图认为它的内容只是第2页到第2页。
例如:
// scrollView has been initialized and added to the view hierarchy according to the link in @richard's answer:
// http://blog.proculo.de/archives/180-Paging-enabled-UIScrollView-With-Previews.html
CGFloat pageNum=10;
CGFloat pageWidth=scrollView.frame.size.width;
CGFloat pageHeight=scrollView.frame.size.height;
CGFloat visibleWidth=320;
// Set scrollView contentSize and create pages:
CGFloat leftShift=floor(((visibleWidth-pageWidth)/2)/pageWidth)*pageWidth;
CGFloat contentSizeReduction=2*leftShift;
scrollView.contentSize = CGSizeMake(pageNum*pageWidth-contentSizeReduction,pageHeight);
for(int i=0; i<pageNum; i++) {
CGRect pageFrame = CGRectMake(i*pageWidth-leftShift, 0, pageWidth, pageHeight);
UIView *pageView = [[[UIView alloc] initWithFrame:pageFrame] autorelease];
// Initialize the page view for the current index here
[scrollView addSubview:pageView];
}
原谅代码中的任何拼写错误。我自己还没有尝试过。
让我知道它是否有效。
当用户在您的页面上滑动时,是否想要滑动一个较小的值,然后scrollView的宽度?首先显示第1,2,3页,然后刷2,3,4?或者4,5,6会在刷卡后显示? – tonklon 2010-07-31 08:36:45
我希望它像一个正常的滚动视图一样行动,滚动应该是手指移动的1:1,但是当手指被移除时它会锁定在页面上。 – Seventoes 2010-08-04 21:37:31