Is there a horizontal UIRefreshControl?

与世无争的帅哥 提交于 2019-12-12 08:06:57

问题


You can add UIRefreshControl to UICollectionView (or any UIScrollView for that matter) by adding it to collection's subviews:

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

This doesn't work when collection view layout has UICollectionViewScrollDirectionHorizontal.

I tried overriding layoutSubviews to put refresh control to the left, but it wouldn't track scrolling progress this way. Can I trick it into working with horizontal layouts?


回答1:


I couldn't find any existing solutions so I extended ODRefreshControl with horizontal layout support:

I needed solution in MonoTouch (C#) so I started by source-porting ODRefreshControl and then patched it to work with horizontal layout.

Full C# source code is here, it should be straightforward to port it back to Objective C.
All I did was add an utility function and some conditions here and there.




回答2:


you can achieve this by implementing 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");

    }
}


来源:https://stackoverflow.com/questions/13810800/is-there-a-horizontal-uirefreshcontrol

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!