Tableview仅弹跳一侧顶侧

Him*_*iya 1 objective-c scrollview uitableview ios

我有一个UITableView,我想,set bouncing only one side top side.但我无法解决这个问题.看到这个视频链接并给我解决方案.任何建议都是欣赏和接受的.

在这里 https://www.dropbox.com/s/qztsfkqoxuy4aaj/question.mov?dl=0

这是我的tableview信息.

Dar*_*ana 7

使用该方法scrollViewDidScroll检查tableview的scrollview的内容偏移量.检查用户是否正在尝试滚动超出表视图的底部边界.如果是这样,请滚动回到tableview的末尾.这不会限制底部弹跳,但会向后滚动,以至于用户不会注意到底部反弹.

   - (void)scrollViewDidScroll:(UIScrollView *)scrollView {
        if (scrollView.contentOffset.y >= scrollView.contentSize.height - scrollView.frame.size.height) {
            [scrollView setContentOffset:CGPointMake(scrollView.contentOffset.x, scrollView.contentSize.height - scrollView.frame.size.height)];
        }
    }
Run Code Online (Sandbox Code Playgroud)

///更新 - 如果Tableview的内容大小将小于其帧,则上面的代码可能无效.在这种情况下你可以使用以下内容:

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

    if(scrollView.contentSize.height > scrollView.frame.size.height)
    {
    if (scrollView.contentOffset.y >= scrollView.contentSize.height - scrollView.frame.size.height) {
       [scrollView setContentOffset:CGPointMake(scrollView.contentOffset.x, scrollView.contentSize.height - scrollView.frame.size.height)];
    }
    }
    else if (scrollView.contentOffset.y >=  0)
    {
         [scrollView setContentOffset:CGPointMake(scrollView.contentOffset.x, 0)];
    }
}
Run Code Online (Sandbox Code Playgroud)