UIScrollView具有多个页面可见或较小的页面大小

Sev*_*oes 6 iphone objective-c uiscrollview ipad ios

我试图让分页同时UIScrollView显示多个页面,实际上,使页面大小小于UIScrollview边界.我一直在谷歌搜索几个小时,但似乎没有人有一个很好的解决方案.

通过调整UIScrollview我想要的页面尺寸,关闭子视图剪辑,并将其放置在将所有点击传递给的页面中,我能够在视觉上获得正确的效果UIScrollview.这样做的问题是,当Y页面可见时,它允许您将最后一页一直向左滚动,在最后一页之后留下Y-1空页面.任何人都知道解决这个问题的方法,或另一种方法来解决问题?

小智 7

我认为你需要像safari移动浏览器中的预览一样.这是一个包含一些示例代码的网站. 预览示例代码


cdu*_*uck 6

对于右端,请尝试减小滚动视图的contentSize属性宽度,以使滚动视图在到达最后一页之前停止分页.对于左端,将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];
}
Run Code Online (Sandbox Code Playgroud)

原谅代码中的任何拼写错误.我自己还没试过这个.

如果有效,请告诉我.