2013-02-17 149 views
1

我正在开发一个在滚动视图中显示大量照片(约650张照片)的应用程序,为了使此应用程序的功能顺利进行,我在scrollView中只添加了三个UIImage,其中一个代表第一页,第二页为当前页面,第三页为下一页,所以当用户首次启动应用程序时,第一个图像将加载到中间页面,最后一个图像将加载到上一页,第二个图像将会加载到下一页,当用户向右滚动时,中间页面将加载第二张图片,上一页将加载第一张图片,下一页将加载第三张图片等。decelerationRate属性不起作用

但是当用户快速滚动滚动视图的界限会出现,阻止用户滚动到下一页,只会博unce。

我的问题是如何使滚动视图滚动速度更快,使-(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

如果你有一个pagingEnabled = YESUIScrollView,然后设置decelerationRate属性将不会对页面的速度产生任何影响(如你发现了)。

为了解决这个问题,您需要设置pagingEnabled = NO并自己手动实现分页功能。请参阅this question and answer了解如何操作。