Dan Abramov Dan Abramov - 1 year ago 53
Objective-C Question

Is there a horizontal UIRefreshControl?

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?

Answer Source

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

enter image description here

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download