Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UITableView bounce bottom edge only

Is it possible to bounce a UITableView on the bottom side, but not the top? If so, please show me code.

like image 377
Jasper Blues Avatar asked Jun 18 '13 10:06

Jasper Blues


2 Answers

Instead of changing the bounces property, I added that to the UIScrollViewDelgate method:

-(void)scrollViewDidScroll:(UIScrollView *)scrollView
{
    if (scrollView.contentOffset.y<=0) {
        scrollView.contentOffset = CGPointZero;
    }
}
like image 109
Liron Berger Avatar answered Oct 04 '22 22:10

Liron Berger


Swift

func scrollViewDidScroll(_ scrollView: UIScrollView) {

     //Check to make sure this only applies to tableview 
     //and not other scrollviews inside your View/ViewController
     if scrollView.superclass == UITableView.self {
     //bounce will only be true if contentOffset.y is higher than 100
     //I set 100 just to make SURE, but you can set >= 0 too
         scrollView.bounces = scrollView.contentOffset.y > 100
     }
        
}

like image 24
shadow of arman Avatar answered Oct 04 '22 22:10

shadow of arman