1

我正在开发一个在滚动视图中显示大量照片(大约 650 张照片)的应用程序,为了使这个应用程序运行顺畅,我在滚动视图中只添加了三个 UIImage,一个代表第一页,第二个代表当前页面第三个用于下一页,所以当用户第一次启动应用程序时,第一张图片将在中间页面加载,最后一张图片将在上一页加载,第二张图片将在下一页加载,当用户向右滚动,中间页面将加载第二张图片,上一页将加载第一张图片,下一页将加载第三张图片,依此类推..

但是当用户快速滚动时,滚动视图的边界会出现,阻止用户滚动到下一页,只会反弹。

我的问题是如何使滚动视图滚动得更快,以便该-(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];

}
4

1 回答 1

0

If you have a UIScrollView with pagingEnabled = YES, then setting the decelerationRate property will not have any effect on the speed of the paging (as you've found out).

To get around this, you will need to set pagingEnabled = NO and manually implement the paging functionality yourself. See this question and answer for how to do this.

于 2013-06-12T12:34:59.030 回答