开发者

reduce bouncing UITableView

开发者 https://www.devze.com 2023-02-21 22:09 出处:网络
is it possible to som开发者_如何学编程ehow reduce the bouncing height at the top or the end of an UITableView?

is it possible to som开发者_如何学编程ehow reduce the bouncing height at the top or the end of an UITableView?

Thank you


You can check and set the contentOffset property in the scrollViewDidScroll method:

-(void)scrollViewDidScroll:(UIScrollView *)scrollView
{    
    if (scrollView.contentOffset.y <= -100)
    {
        CGPoint offset = scrollView.contentOffset;
        offset.y = -100;
        scrollView.contentOffset = offset;
    }    
}


Not without disabling it entirely, via the UIScrollView property bounces. It's pretty much an on-or-off thing.


I doubt so. The elasticity of scroll views is an implementation detail and it doesn't appear that the UIScrollView class exposes properties that let you adjust that.


As additional to René Fischer answer follow the full code to reduce bounce top and bottom.

Swift Version:

override func scrollViewDidScroll(scrollView: UIScrollView) {

    var offset = scrollView.contentOffset;

    if (offset.y < bounceLimit) {
        offset.y = bounceLimit;
        scrollView.contentOffset = offset;
    }

    let offsetY = scrollView.contentSize.height - scrollView.bounds.height - offset.y
    if (offsetY < bounceLimit) {
        offset.y = scrollView.contentOffset.y - (bounceLimit + abs(offsetY));
        scrollView.contentOffset = offset;
    }
}

Obj-C Version:

-(void)scrollViewDidScroll:(UIScrollView *)scrollView
{
    CGPoint offset = scrollView.contentOffset;

    if (offset.y <= -100)
    {
        offset.y = -100;
        scrollView.contentOffset = offset;
    }

    CGFloat offsetY = scrollView.contentSize.height - scrollView.bounds.height - offset.y

    if (offsetY < bounceLimit) {
        offset.y = offset.y - (bounceLimit + abs(offsetY));
        scrollView.contentOffset = offset;
    }
}

Note: The height of the table (contentSize.height) should be at least the device screen height less the bounce limit.


You cannot changing bounceing property of scrollview either you can disable or enable

0

精彩评论

暂无评论...
验证码 换一张
取 消