iosuiscrollviewuicollectionviewhorizontalscrollviewpull-to-refresh

UIRefreshControl( pull left to right refresh ) concept in UICollectionView horizontally


I have a custom horizontal collection view that has 1 row and I want to add pull to refresh functionality which, by default, appears above my row of cells. I would like the user to be able to pull the collection view from left to right to activate the UIRefreshControl. Any ideas?


Solution

  • For this you need to implement the UIScrollViewDelegate method

    - (void)scrollViewDidScroll:(UIScrollView *)scrollView {
         CGPoint offset = scrollView.contentOffset;
         CGRect bounds = scrollView.bounds;
         CGSize size = scrollView.contentSize;
         UIEdgeInsets inset = scrollView.contentInset;
         float y = offset.x + bounds.size.width - inset.right;
         float h = size.width;
    
    
        float reload_distance = 75; //distance for which you want to load more
        if(y > h + reload_distance) {
         // write your code getting the more data
           NSLog(@"load more rows");
    
        }
    

    }