带预加载的UIScrollView分页

时间:2012-07-20 09:04:34

标签: ios uiscrollview paging

我实现了一个分页UIScrollView。因此,我的滚动视图中有5个子视图。为了获得良好的效果,我为每个子视图设置了一个小偏移,这样在第一页上,你可以看到ipad右侧第二页的一点点。对其他页面的效果相同,因此每次进入页面时,您都会在屏幕的左/右侧进行一些预览。页面之间的滚动效果很好,但问题是,第一次没有加载预览。我在每个子视图上都有一个textview,但在滚动到下一页后它会先加载。所以我的预览不正确。如何进行预加载,以便在切换到其他子视图页面之前加载?

感谢您的帮助,我希望我能解释清楚...... 安迪

preview page loading

代码:

XIB: 我有一个UIScrollView,大小750,700.我的Customview是700,700。

resultScrollView.clipsToBounds = NO;
resultScrollView.pagingEnabled = YES;
resultScrollView.showsHorizontalScrollIndicator = YES;

[resultScrollView addSubview:[self createCustomSubView:0.0f :VIEW_OFFSET_BETWEEN :VIEW_WIDTH :VIEW_HEIGHT]];
[resultScrollView addSubview:[self createCustomSubView.frame.size.width :VIEW_OFFSET_BETWEEN :VIEW_WIDTH :VIEW_HEIGHT]];
[resultScrollView addSubview:[self createCustomSubView:2*resultScrollView.frame.size.width :VIEW_OFFSET_BETWEEN :VIEW_WIDTH :VIEW_HEIGHT]];
[resultScrollView addSubview:[self createCustomSubView:3*resultScrollView.frame.size.width :VIEW_OFFSET_BETWEEN :VIEW_WIDTH :VIEW_HEIGHT]];
[resultScrollView addSubview:[self createCustomSubView:4*resultScrollView.frame.size.width :VIEW_OFFSET_BETWEEN :VIEW_WIDTH :VIEW_HEIGHT]];

resultScrollView.contentSize = CGSizeMake(5*resultScrollView.frame.size.width+5*VIEW_OFFSET_BETWEEN, resultScrollView.frame.size.height);

方法:

CGRect frame = CGRectMake(contentOffset + betweenOffset, 0.0f, width, height);
NSArray *subviewArray = [[NSBundle mainBundle] loadNibNamed:@"CustomSubview" owner:self options:nil];
CustomSubview *customSubView = [subviewArray objectAtIndex:0];
CustomSubview.frame = frame;
CustomSubview.contentMode = UIViewContentModeCenter;
CustomSubview.contentSize = CGSizeMake(VIEW_SCROLLABLE_CONTENT_WIDTH, VIEW_SCROLLABLE_CONTENT_HEIGHT);

0 个答案:

没有答案
相关问题