我正在开发一个在滚动视图中显示大量照片(约650张照片)的应用程序,以使此应用程序功能流畅,我在scrollView中只添加了三个UIImages,一个代表第一页,第二个代表当前一个和下一个页面的第三个,所以当用户首次启动应用程序时,第一个图像将加载到中间页面,最后一个图像将加载到上一页面,第二个图像将加载到下一页面,当用户向右滚动时,中间页面将加载第二个图像,上一页面将加载第一个图像,下一页面将加载第三个图像,依此类推。
但是当用户快速滚动时,滚动视图的边界将会出现,阻止用户滚动到下一页并且只会反弹。
我的问题是如何让滚动视图滚动得更快,以便-(void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
方法可以更快地调用
我尝试了decelerationRate
属性,如下面的代码所示,但我没有注意到任何差异!我使用它还是有问题?
提前致谢
- (void)viewDidLoad
{
scrollView = [[ScrollView alloc]initWithFrame:CGRectMake(0, 0, 320, 480)];
scrollView.delegate = self;
//scrollView.decelerationRate= UIScrollViewDecelerationRateFast;
[self.view addSubview:scrollView];
scrollView.contentSize = CGSizeMake(960, 416);
pageZero = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 320, 480)];
pageOne = [[UIImageView alloc]initWithFrame:CGRectMake(320, 0, 320, 480)];
pageTwo = [[UIImageView alloc]initWithFrame:CGRectMake(640, 0, 320, 480)];
//set array that holds images to be shown
for(int i = 0 ; i < 10 ; i++)
[pages addObject:[NSString stringWithFormat:@"%i.png",i]];
//load photos
[self loadPageWithId:0 onPage:1];
[self loadPageWithId:2 onPage:0];
[self loadPageWithId:1 onPage:2];
//add 3 UIImage objects to the scrollView
[scrollView addSubview:pageZero];
[scrollView addSubview:pageOne];
[scrollView addSubview:pageTwo];
//scroll to the middle page without animation
[scrollView scrollRectToVisible:CGRectMake(320,0,320,416) animated:NO];
UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(singleTap)];
[self.scrollView addGestureRecognizer:singleTap];
}
答案 0 :(得分:0)
如果您有UIScrollView
pagingEnabled = YES
,那么设置decelerationRate
属性不会对分页速度产生任何影响(如您所知)。
要解决此问题,您需要设置pagingEnabled = NO
并自行手动实现分页功能。有关如何执行此操作,请参阅this question and answer。