减速后UIScrollView反弹一下(UIScrollView bounces a little after decelerating)

编程入门 行业动态 更新时间:2024-10-06 04:03:41
减速后UIScrollView反弹一下(UIScrollView bounces a little after decelerating)

我有scrollView with 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。

I have scrollView with pagingScrollView.pagingEnabled = YES;. After flicking to next page the scrollView bounces a little after decelerating, here is my log origin.x change with comments:

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

How could this happen? The width of frame is 768px.

最满意答案

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

UPD:

我还是不知道 - 为什么会这样。 我检查了Apple的PhotoScroller样本,这件事也发生在那里。 我发现这个解决方法 - 可能它不是很好,但它的工作原理:

我正在等待此事件发生:

-(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];

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

I have the same issue. Turning off bouncing does nothing.

UPD:

I still do not know - why is this happening. I checked the PhotoScroller sample from Apple, and this thing also happening there. I found this workaround - may be it is not quite good, but it works:

I am waiting for this event to occure:

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

and then just setting the correct position of the content:

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];

Then the scroll view is scrolling right to the position I specified, without any 'tail bouncing'

更多推荐

本文发布于:2023-07-09 10:26:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1085619.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:UIScrollView   bounces   decelerating

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!