【问题标题】:Is there a horizontal UIRefreshControl?有水平的 UIRefreshControl 吗?
【发布时间】:2012-12-10 23:01:31
【问题描述】:

您可以通过adding it to collection's subviewsUIRefreshControl 添加到UICollectionView(或任何UIScrollView):

UIRefreshControl *refreshControl = [[UIRefreshControl alloc] init];
[refreshControl addTarget:self action:@selector(handleRefresh:) forControlEvents:UIControlEventValueChanged];
[self.collectionView addSubview:refreshControl];

当集合视图布局具有 UICollectionViewScrollDirectionHorizontal 时,这不起作用。

我尝试覆盖layoutSubviews 将刷新控件放在左侧,但它不会以这种方式跟踪滚动进度。我可以欺骗它使用水平布局吗?

【问题讨论】:

  • 也许我比较保守,但是尽管您可以通过这种方式添加此视图并使其正常工作,但我认为它不是为此而设计的,文档确实将其明确链接到 UITableView .
  • @Daniel 虽然这是真的,但我看到这里有很多人这样做,这让我觉得 Apple 可能会将这种事实上的工作行为正式化。我也没有看到一篇帖子说他们的应用因使用 UIRefreshControl 而没有表格视图而被拒绝。

标签: objective-c uiscrollview ios6 uikit uirefreshcontrol


【解决方案1】:

我找不到任何现有的解决方案,所以我扩展了 ODRefreshControl 以支持水平布局:

我需要 MonoTouch (C#) 中的解决方案,因此我首先将源代码移植到 ODRefreshControl,然后使用水平布局移植 patched it to work

完整的 C# 源代码是 here,应该可以直接将其移植回 Objective C。
我所做的只是在这里和那里添加一个实用函数和一些条件。

【讨论】:

  • 您好,您能提供带有objective-c 的扩展代码吗?谢谢!
  • @Dan 请提供您在 Obj-C 中制作的代码,请提供您的代码
【解决方案2】:

您可以通过实现 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");

    }
}

【讨论】:

    猜你喜欢
    • 2013-06-20
    • 1970-01-01
    • 2019-11-04
    • 2014-05-11
    • 2021-05-12
    • 2012-09-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多