【问题标题】:UIRefreshControl( pull left to right refresh ) concept in UICollectionView horizontallyUICollectionView中的UIRefreshControl(从左到右刷新)概念水平
【发布时间】:2014-05-11 17:06:45
【问题描述】:

我有一个自定义的水平集合视图,它有 1 行,我想添加拉动刷新功能,默认情况下,它显示在我的单元格行上方。我希望用户能够从左到右拉集合视图以激活 UIRefreshControl。有什么想法吗?

【问题讨论】:

  • 使用有帮助的手势

标签: ios uiscrollview uicollectionview horizontalscrollview pull-to-refresh


【解决方案1】:

为此你需要实现 UIScrollViewDelegate 方法

- (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");

    }

}

【讨论】:

    【解决方案2】:

    使用这个http://code4app.net/ios/RefreshView/5247b46b6803fa7304000000.it来刷新视图,同样的方式你可以刷新collectionView。

    【讨论】:

    【解决方案3】:

    更新了 Nitin 对 Swift 5.0 的回答

     override func scrollViewDidScroll(_ scrollView: UIScrollView) {
                let offset = scrollView.contentOffset
                let bounds = scrollView.bounds
                let size = scrollView.contentSize
                let inset = scrollView.contentInset
                let y = offset.x + bounds.size.width - inset.right
                let h = size.width
                
                let reload_distance = 75 //distance for which you want to load more
                if y > h + CGFloat(reload_distance) {
                    //reload
                    reload()
                }
                
            }
    

    【讨论】:

      猜你喜欢
      • 2017-12-31
      • 2019-10-22
      • 2013-06-20
      • 2014-07-16
      • 2021-12-09
      • 2016-06-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多