UIScrollView tends to “snap” back to a previous position

蹲街弑〆低调 提交于 2019-12-12 15:06:07

问题


I'm using a UIScrollerView and I found that it tends to "snap" back to a previous position when I scroll it.

I would like to simulate the behavior if the UItableView's scroller, that stays in the position where the user released his finger.

The properties set:

[scroller setCanCancelContentTouches:NO];
scroller.clipsToBounds = YES;   
[scroller setScrollEnabled:YES];
scroller.userInteractionEnabled = YES;
scroller.alwaysBounceHorizontal = YES;
scroller.alwaysBounceVertical= NO;
scroller.showsVerticalScrollIndicator = NO;
scroller.scrollsToTop = NO;
scroller.bounces = NO;
scroller.pagingEnabled = NO;

回答1:


There a few possible reasons for the snap back.

One could be that you have pagingEnabled set to YES which means that when the user lets go their finger, it will snap to the closest page boundary.

Another is that you have the contentSize set incorrectly. This is not the problem if you can actually scroll to the top and bottom and leave it there without it bouncing away.




回答2:


- (void)scrollViewDidScroll:(UIScrollView *)sender {
    int scrollDirection;
    if (lastContentOffset > self.scrollView.contentOffset.x){
        scrollDirection = RIGHT;



        NSLog(@"right");
    }
    else if (lastContentOffset < self.scrollView.contentOffset.x) {
        scrollDirection = LEFT;
        NSLog(@"left");
        lastContentOffset = self.scrollView.contentOffset.x;



    }

}

- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView {

    lastContentOffset = self.scrollView.contentOffset.x;

}


来源:https://stackoverflow.com/questions/1520908/uiscrollview-tends-to-snap-back-to-a-previous-position

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!