4

我有滚动视图pagingScrollView.pagingEnabled = YES;。滑动到下一页后,scrollView 在减速后会反弹一点,这是我的日志 origin.x 更改并带有注释:

2010-11-03 12:53:09.187 app[84864:207] scrollview.bound.origin.x: 713.000000 << deccelerating..
2010-11-03 12:53:09.199 app[84864:207] scrollview.bound.origin.x: 727.000000
2010-11-03 12:53:09.212 app[84864:207] scrollview.bound.origin.x: 738.000000
2010-11-03 12:53:09.230 app[84864:207] scrollview.bound.origin.x: 747.000000
2010-11-03 12:53:09.248 app[84864:207] scrollview.bound.origin.x: 754.000000
2010-11-03 12:53:09.262 app[84864:207] scrollview.bound.origin.x: 759.000000
2010-11-03 12:53:09.278 app[84864:207] scrollview.bound.origin.x: 763.000000
2010-11-03 12:53:09.295 app[84864:207] scrollview.bound.origin.x: 766.000000
2010-11-03 12:53:09.312 app[84864:207] scrollview.bound.origin.x: 768.000000 <<at this origin.y, should stop deccelerating
2010-11-03 12:53:09.328 app[84864:207] scrollview.bound.origin.x: 769.000000 <<bounce ?
2010-11-03 12:53:09.377 app[84864:207] scrollview.bound.origin.x: 770.000000 <<bounce ?
2010-11-03 12:53:09.378 app[84864:207] scrollview.bound.origin.x: 769.000000 <<bounce ?
2010-11-03 12:53:09.395 app[84864:207] scrollview.bound.origin.x: 768.000000 <<stopped

这怎么可能发生?框架宽度为 768px。

4

1 回答 1

4

我有同样的问题。关闭弹跳没有任何作用。

升级版:

我仍然不知道 - 为什么会这样。我检查了 Apple 的 PhotoScroller 样本,这件事也发生在那里。我找到了这个解决方法 - 可能不是很好,但它有效:

  1. 我正在等待这个事件发生:

    -(void)scrollViewWillBeginDecelerating:(UIScrollView *)scrollView; 
    

然后只需设置内容的正确位置:

CGFloat pageWidth = pagingScrollView.bounds.size.width;
NSInteger curPage = currentPage;

if (firstTapPoint.x > lastTapPoint.x) {
    //NSLog(@"Going prev page");
    curPage = (curPage==0)?0:(currentPage-1);
}else if(firstTapPoint.x < lastTapPoint.x){
    //NSLog(@"Going next page");
    curPage = (currentPage==([self imageCount]-1))?currentPage:(currentPage+1);
}else if(firstTapPoint.x == lastTapPoint.x) {
    //NSLog(@"Staying on the same page");       
}

//NSLog(@"Current page is %d and the next page is %d", currentPage, curPage);

CGPoint finalOffset = CGPointMake(pageWidth * curPage, 0);
[scrollView setContentOffset:finalOffset animated:YES];

然后滚动视图向右滚动到我指定的位置,没有任何“尾巴弹跳”

于 2010-11-12T10:37:45.103 回答